OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "ui/gfx/geometry/insets.h" | 12 #include "ui/gfx/geometry/insets.h" |
13 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
14 #include "ui/views/animation/ink_drop_host_view.h" | 14 #include "ui/views/animation/ink_drop_host_view.h" |
15 #include "ui/views/animation/ink_drop_observer.h" | |
16 #include "ui/views/controls/button/custom_button.h" | |
15 #include "ui/views/controls/label.h" | 17 #include "ui/views/controls/label.h" |
18 #include "ui/views/widget/widget_observer.h" | |
16 | 19 |
17 namespace gfx { | 20 namespace gfx { |
18 class Canvas; | |
19 class FontList; | 21 class FontList; |
20 class ImageSkia; | 22 class ImageSkia; |
21 } | 23 } |
22 | 24 |
23 namespace views { | 25 namespace views { |
24 class ImageView; | 26 class ImageView; |
25 class Label; | 27 class InkDropContainerView; |
28 class InkDropMask; | |
26 } | 29 } |
27 | 30 |
28 // View used to draw a bubble, containing an icon and a label. We use this as a | 31 // View used to draw a bubble, containing an icon and a label. We use this as a |
29 // base for the classes that handle the location icon (including the EV bubble), | 32 // base for the classes that handle the location icon (including the EV bubble), |
30 // tab-to-search UI, and content settings. | 33 // tab-to-search UI, and content settings. |
31 class IconLabelBubbleView : public views::InkDropHostView { | 34 class IconLabelBubbleView : public views::InkDropObserver, |
35 public views::CustomButton, | |
36 public views::ButtonListener, | |
37 public views::WidgetObserver { | |
32 public: | 38 public: |
33 static constexpr int kTrailingPaddingPreMd = 2; | 39 static constexpr int kTrailingPaddingPreMd = 2; |
34 | 40 |
35 IconLabelBubbleView(const gfx::FontList& font_list, bool elide_in_middle); | 41 IconLabelBubbleView(const gfx::FontList& font_list, bool elide_in_middle); |
36 ~IconLabelBubbleView() override; | 42 ~IconLabelBubbleView() override; |
37 | 43 |
44 // views::InkDropObserver: | |
45 void InkDropAnimationStarted() override; | |
46 | |
47 // views::ButtonListener: | |
48 void ButtonPressed(Button* sender, const ui::Event& event) override; | |
49 | |
38 void SetLabel(const base::string16& label); | 50 void SetLabel(const base::string16& label); |
39 void SetImage(const gfx::ImageSkia& image); | 51 void SetImage(const gfx::ImageSkia& image); |
40 | 52 |
41 const views::ImageView* GetImageView() const { return image_; } | 53 const views::ImageView* GetImageView() const { return image_; } |
42 views::ImageView* GetImageView() { return image_; } | 54 views::ImageView* GetImageView() { return image_; } |
43 | 55 |
44 protected: | 56 protected: |
45 static constexpr int kOpenTimeMS = 150; | 57 static constexpr int kOpenTimeMS = 150; |
46 | 58 |
47 views::ImageView* image() { return image_; } | 59 views::ImageView* image() { return image_; } |
(...skipping 16 matching lines...) Expand all Loading... | |
64 // full-width view and can be used to animate the width of the view. | 76 // full-width view and can be used to animate the width of the view. |
65 virtual double WidthMultiplier() const; | 77 virtual double WidthMultiplier() const; |
66 | 78 |
67 // Returns true when animation is in progress and is shrinking. | 79 // Returns true when animation is in progress and is shrinking. |
68 virtual bool IsShrinking() const; | 80 virtual bool IsShrinking() const; |
69 | 81 |
70 // The view has been activated by a user gesture such as spacebar. Returns | 82 // The view has been activated by a user gesture such as spacebar. Returns |
71 // true if some handling was performed. | 83 // true if some handling was performed. |
72 virtual bool OnActivate(const ui::Event& event); | 84 virtual bool OnActivate(const ui::Event& event); |
73 | 85 |
86 // Returns true if the bubble anchored to the icon is shown. This is to | |
87 // prevent the bubble from reshowing on a mouse release. | |
88 virtual bool IsBubbleShown() const; | |
89 | |
74 // views::InkDropHostView: | 90 // views::InkDropHostView: |
75 gfx::Size GetPreferredSize() const override; | 91 gfx::Size GetPreferredSize() const override; |
76 void Layout() override; | 92 void Layout() override; |
93 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | |
94 bool OnMousePressed(const ui::MouseEvent& event) override; | |
95 | |
96 // void OnMouseReleased(const ui::MouseEvent& event) override; | |
77 bool OnKeyPressed(const ui::KeyEvent& event) override; | 97 bool OnKeyPressed(const ui::KeyEvent& event) override; |
78 bool OnKeyReleased(const ui::KeyEvent& event) override; | 98 bool OnKeyReleased(const ui::KeyEvent& event) override; |
79 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | 99 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
80 void OnNativeThemeChanged(const ui::NativeTheme* native_theme) override; | 100 void OnNativeThemeChanged(const ui::NativeTheme* native_theme) override; |
81 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; | 101 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; |
82 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; | 102 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; |
103 std::unique_ptr<views::InkDrop> CreateInkDrop() override; | |
83 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() | 104 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() |
84 const override; | 105 const override; |
106 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; | |
107 std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override; | |
85 SkColor GetInkDropBaseColor() const override; | 108 SkColor GetInkDropBaseColor() const override; |
86 | 109 |
110 // views::CustomButton: | |
111 bool IsTriggerableEvent(const ui::Event& event) override; | |
112 void OnClickCanceled(const ui::Event& event) override; | |
113 | |
114 // views::WidgetObserver: | |
115 void OnWidgetDestroying(views::Widget* widget) override; | |
116 void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override; | |
117 | |
87 const gfx::FontList& font_list() const { return label_->font_list(); } | 118 const gfx::FontList& font_list() const { return label_->font_list(); } |
88 | 119 |
89 SkColor GetParentBackgroundColor() const; | 120 SkColor GetParentBackgroundColor() const; |
90 | 121 |
91 gfx::Size GetSizeForLabelWidth(int label_width) const; | 122 gfx::Size GetSizeForLabelWidth(int label_width) const; |
92 | 123 |
93 private: | 124 private: |
125 // A view that draws the separator. | |
126 class SeparatorView : public views::View { | |
127 public: | |
128 explicit SeparatorView(IconLabelBubbleView* owner); | |
129 | |
130 // views::View: | |
131 void OnPaint(gfx::Canvas* canvas) override; | |
132 bool CanProcessEventsWithinSubtree() const override; | |
133 | |
134 // Updates the opacity based on the ink drop's state. | |
135 void UpdateOpacity(); | |
136 | |
137 private: | |
138 // Weak. | |
139 IconLabelBubbleView* owner_; | |
140 }; | |
141 | |
94 // Amount of padding from the leading edge of the view to the leading edge of | 142 // Amount of padding from the leading edge of the view to the leading edge of |
95 // the image, and from the trailing edge of the label (or image, if the label | 143 // the image, and from the trailing edge of the label (or image, if the label |
96 // is invisible) to the trailing edge of the view. | 144 // is invisible) to the trailing edge of the view. |
97 int GetOuterPadding() const; | 145 int GetOuterPadding() const; |
98 | 146 |
99 // Spacing between the image and the label. | 147 // Spacing between the image and the label. |
100 int GetInternalSpacing() const; | 148 int GetInternalSpacing() const; |
101 | 149 |
102 // Padding after the separator. | 150 // Padding after the separator. |
103 int GetPostSeparatorPadding() const; | 151 int GetPostSeparatorPadding() const; |
104 | 152 |
105 float GetScaleFactor() const; | 153 float GetScaleFactor() const; |
106 | 154 |
107 // views::View: | 155 // views::View: |
108 const char* GetClassName() const override; | 156 const char* GetClassName() const override; |
109 void OnPaint(gfx::Canvas* canvas) override; | |
110 | 157 |
111 // The contents of the bubble. | 158 // The contents of the bubble. |
112 views::ImageView* image_; | 159 views::ImageView* image_; |
113 views::Label* label_; | 160 views::Label* label_; |
161 views::InkDropContainerView* ink_drop_container_; | |
162 std::unique_ptr<views::InkDropMask> ink_drop_mask_; | |
163 std::unique_ptr<SeparatorView> separator_view_; | |
114 | 164 |
115 // The padding of the element that will be displayed after |this|. This value | 165 // The padding of the element that will be displayed after |this|. This value |
116 // is relevant for calculating the amount of space to reserve after the | 166 // is relevant for calculating the amount of space to reserve after the |
117 // separator. | 167 // separator. |
118 int next_element_interior_padding_ = 0; | 168 int next_element_interior_padding_ = 0; |
119 | 169 |
170 // This is used to check if the bubble was showing during the mouse pressed | |
171 // event. If this is true then the OnButtonPressed() call is ignored to | |
172 // prevent the bubble from reshowing. This flag is necessary because | |
173 // OnButtonPressed() is called during the mouse released event. | |
174 bool suppress_button_action_; | |
bruthig
2017/03/22 17:20:16
Instead of manually tracking this, would it be pos
spqchan
2017/03/24 17:58:03
The expected behavior is to notify on release, esp
bruthig
2017/03/24 20:48:02
Right, I guess it just seems odd that this needs t
spqchan
2017/03/27 23:41:51
I added a comment that explains this and modified
| |
175 | |
120 DISALLOW_COPY_AND_ASSIGN(IconLabelBubbleView); | 176 DISALLOW_COPY_AND_ASSIGN(IconLabelBubbleView); |
121 }; | 177 }; |
122 | 178 |
123 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_ | 179 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_ |
OLD | NEW |