forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshelf_navigation_widget.h
140 lines (105 loc) · 4.23 KB
/
shelf_navigation_widget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SHELF_SHELF_NAVIGATION_WIDGET_H_
#define ASH_SHELF_SHELF_NAVIGATION_WIDGET_H_
#include <memory>
#include "ash/ash_export.h"
#include "ash/shelf/shelf_component.h"
#include "ui/views/accessible_pane_view.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
namespace aura {
class Window;
}
namespace views {
class BoundsAnimator;
}
namespace ash {
class BackButton;
class HomeButton;
class NavigationButtonAnimationMetricsReporter;
class Shelf;
class ShelfView;
// The shelf navigation widget holds the home button and (when in tablet mode)
// the back button.
class ASH_EXPORT ShelfNavigationWidget : public ShelfComponent,
public views::Widget {
public:
class TestApi {
public:
explicit TestApi(ShelfNavigationWidget* widget);
~TestApi();
// Whether the home button view is visible.
bool IsHomeButtonVisible() const;
// Whether the back button view is visible.
bool IsBackButtonVisible() const;
views::BoundsAnimator* GetBoundsAnimator();
private:
ShelfNavigationWidget* navigation_widget_;
};
ShelfNavigationWidget(Shelf* shelf, ShelfView* shelf_view);
~ShelfNavigationWidget() override;
// Initializes the widget, sets its contents view and basic properties.
void Initialize(aura::Window* container);
// views::Widget:
void OnMouseEvent(ui::MouseEvent* event) override;
void OnScrollEvent(ui::ScrollEvent* event) override;
bool OnNativeWidgetActivationChanged(bool active) override;
void OnGestureEvent(ui::GestureEvent* event) override;
// Getter for the back button view - nullptr if the back button should not be
// shown for the current shelf configuration.
BackButton* GetBackButton() const;
// Getter for the home button view - nullptr if the home button should not be
// shown for the current shelf configuration.
HomeButton* GetHomeButton() const;
// Sets whether the last focusable child (instead of the first) should be
// focused when activating this widget.
void SetDefaultLastFocusableChild(bool default_last_focusable_child);
// ShelfComponent:
void CalculateTargetBounds() override;
gfx::Rect GetTargetBounds() const override;
void UpdateLayout(bool animate) override;
void UpdateTargetBoundsForGesture(int shelf_position) override;
// Returns the visible part's bounds in screen coordinates.
gfx::Rect GetVisibleBounds() const;
// Called when shelf layout manager detects a locale change. Reloads the
// home and back button tooltips and accessibility name strings.
void HandleLocaleChange();
const views::BoundsAnimator* bounds_animator_for_test() const {
return bounds_animator_.get();
}
private:
class Delegate;
void UpdateButtonVisibility(
views::View* button,
bool visible,
bool animate,
NavigationButtonAnimationMetricsReporter* metrics_reporter);
// Returns the clip rectangle.
gfx::Rect CalculateClipRect() const;
// Returns the ideal size of the whole widget or the visible area only when
// |only_visible_area| is true.
gfx::Size CalculateIdealSize(bool only_visible_area) const;
// Returns the number of visible control buttons.
int CalculateButtonCount() const;
Shelf* shelf_ = nullptr;
Delegate* delegate_ = nullptr;
// In tablet mode with hotseat enabled, |clip_rect_| is used to hide the
// invisible widget part.
gfx::Rect clip_rect_;
// The target widget bounds in screen coordinates.
gfx::Rect target_bounds_;
std::unique_ptr<views::BoundsAnimator> bounds_animator_;
// Animation metrics reporter for back button animations. Owned by the
// Widget to ensure it outlives the BackButton view.
std::unique_ptr<NavigationButtonAnimationMetricsReporter>
back_button_metrics_reporter_;
// Animation metrics reporter for home button animations. Owned by the
// Widget to ensure it outlives the HomeButton view.
std::unique_ptr<NavigationButtonAnimationMetricsReporter>
home_button_metrics_reporter_;
DISALLOW_COPY_AND_ASSIGN(ShelfNavigationWidget);
};
} // namespace ash
#endif // ASH_SHELF_SHELF_NAVIGATION_WIDGET_H_