1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef ASH_SYSTEM_STATUS_AREA_WIDGET_DELEGATE_H_
6 #define ASH_SYSTEM_STATUS_AREA_WIDGET_DELEGATE_H_
7 
8 #include "ash/ash_export.h"
9 #include "ash/public/cpp/shelf_config.h"
10 #include "ash/public/cpp/shelf_types.h"
11 #include "ash/system/status_area_widget.h"
12 #include "base/macros.h"
13 #include "ui/gfx/image/image_skia.h"
14 #include "ui/views/accessible_pane_view.h"
15 #include "ui/views/widget/widget_delegate.h"
16 
17 namespace ash {
18 class FocusCycler;
19 class Shelf;
20 
21 // The View for the status area widget.
22 class ASH_EXPORT StatusAreaWidgetDelegate : public views::AccessiblePaneView,
23                                             public views::WidgetDelegate {
24  public:
25   explicit StatusAreaWidgetDelegate(Shelf* shelf);
26   ~StatusAreaWidgetDelegate() override;
27 
28   // Calculates the bounds that this view should have given its constraints,
29   // but does not actually update bounds yet.
30   void CalculateTargetBounds();
31 
32   // Returns the bounds that this view should have given its constraints.
33   gfx::Rect GetTargetBounds() const;
34 
35   // Performs the actual changes in bounds for this view to match its target
36   // bounds.
37   void UpdateLayout(bool animate);
38 
39   // Sets the focus cycler.
40   void SetFocusCyclerForTesting(const FocusCycler* focus_cycler);
41 
42   // If |reverse|, indicates backward focusing, otherwise forward focusing.
43   // Returns true if status area widget delegate should focus out on the
44   // designated focusing direction, otherwise false.
45   bool ShouldFocusOut(bool reverse);
46 
47   // Called by StatusAreaWidget when its collapse state changes.
48   void OnStatusAreaCollapseStateChanged(
49       StatusAreaWidget::CollapseState new_collapse_state);
50 
51   // views::AccessiblePaneView:
52   View* GetDefaultFocusableChild() override;
53   const char* GetClassName() const override;
54   views::Widget* GetWidget() override;
55   const views::Widget* GetWidget() const override;
56 
57   // ui::EventHandler:
58   void OnGestureEvent(ui::GestureEvent* event) override;
59 
60   // views::WidgetDelegate:
61   bool CanActivate() const override;
62 
set_default_last_focusable_child(bool default_last_focusable_child)63   void set_default_last_focusable_child(bool default_last_focusable_child) {
64     default_last_focusable_child_ = default_last_focusable_child;
65   }
66 
67  protected:
68   // views::View:
69   void ChildPreferredSizeChanged(views::View* child) override;
70   void ChildVisibilityChanged(views::View* child) override;
71 
72  private:
73   // Sets a border on |child|. If |extend_border_to_edge| is true, then an extra
74   // wide border is added to extend the view's hit region to the edge of the
75   // screen.
76   void SetBorderOnChild(views::View* child, bool extend_border_to_edge);
77 
78   Shelf* const shelf_;
79   const FocusCycler* focus_cycler_for_testing_;
80   gfx::Rect target_bounds_;
81 
82   // When true, the default focus of the status area widget is the last
83   // focusable child.
84   bool default_last_focusable_child_ = false;
85 
86   DISALLOW_COPY_AND_ASSIGN(StatusAreaWidgetDelegate);
87 };
88 
89 }  // namespace ash
90 
91 #endif  // ASH_SYSTEM_STATUS_AREA_WIDGET_DELEGATE_H_
92