Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: chrome/browser/ui/views/location_bar/icon_label_bubble_view.h

Issue 2720183002: [Views] Update ink drop for omnibox icons (Closed)
Patch Set: Fix for bruthig Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
26 } 28 }
27 29
28 // View used to draw a bubble, containing an icon and a label. We use this as a 30 // 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), 31 // base for the classes that handle the location icon (including the EV bubble),
30 // tab-to-search UI, and content settings. 32 // tab-to-search UI, and content settings.
31 class IconLabelBubbleView : public views::InkDropHostView { 33 class IconLabelBubbleView : public views::InkDropObserver,
34 public views::CustomButton,
35 public views::ButtonListener,
36 public views::WidgetObserver {
32 public: 37 public:
33 static constexpr int kTrailingPaddingPreMd = 2; 38 static constexpr int kTrailingPaddingPreMd = 2;
34 39
35 IconLabelBubbleView(const gfx::FontList& font_list, bool elide_in_middle); 40 IconLabelBubbleView(const gfx::FontList& font_list, bool elide_in_middle);
36 ~IconLabelBubbleView() override; 41 ~IconLabelBubbleView() override;
37 42
43 // views::InkDropObserver:
44 void InkDropAnimationStarted() override;
45
46 // views::ButtonListener:
47 void ButtonPressed(Button* sender, const ui::Event& event) override;
sky 2017/05/05 23:40:20 It's mildly weird that this is a subclass of Custo
spqchan 2017/05/10 19:22:11 Done.
48
38 void SetLabel(const base::string16& label); 49 void SetLabel(const base::string16& label);
39 void SetImage(const gfx::ImageSkia& image); 50 void SetImage(const gfx::ImageSkia& image);
40 51
41 const views::ImageView* GetImageView() const { return image_; } 52 const views::ImageView* GetImageView() const { return image_; }
42 views::ImageView* GetImageView() { return image_; } 53 views::ImageView* GetImageView() { return image_; }
43 54
44 protected: 55 protected:
45 static constexpr int kOpenTimeMS = 150; 56 static constexpr int kOpenTimeMS = 150;
46 57
47 views::ImageView* image() { return image_; } 58 views::ImageView* image() { return image_; }
48 const views::ImageView* image() const { return image_; } 59 const views::ImageView* image() const { return image_; }
49 views::Label* label() { return label_; } 60 views::Label* label() { return label_; }
50 const views::Label* label() const { return label_; } 61 const views::Label* label() const { return label_; }
62 const views::InkDropContainerView* ink_drop_container() const {
63 return ink_drop_container_;
64 }
51 65
52 void set_next_element_interior_padding(int padding) { 66 void set_next_element_interior_padding(int padding) {
53 next_element_interior_padding_ = padding; 67 next_element_interior_padding_ = padding;
54 } 68 }
55 69
56 // Gets the color for displaying text. 70 // Gets the color for displaying text.
57 virtual SkColor GetTextColor() const = 0; 71 virtual SkColor GetTextColor() const = 0;
58 72
59 // Returns true when the label should be visible. 73 // Returns true when the label should be visible.
60 virtual bool ShouldShowLabel() const; 74 virtual bool ShouldShowLabel() const;
61 75
62 // Returns a multiplier used to calculate the actual width of the view based 76 // Returns a multiplier used to calculate the actual width of the view based
63 // on its desired width. This ranges from 0 for a zero-width view to 1 for a 77 // on its desired width. This ranges from 0 for a zero-width view to 1 for a
64 // full-width view and can be used to animate the width of the view. 78 // full-width view and can be used to animate the width of the view.
65 virtual double WidthMultiplier() const; 79 virtual double WidthMultiplier() const;
66 80
67 // Returns true when animation is in progress and is shrinking. 81 // Returns true when animation is in progress and is shrinking.
68 virtual bool IsShrinking() const; 82 virtual bool IsShrinking() const;
69 83
70 // The view has been activated by a user gesture such as spacebar. Returns 84 // Returns true if a bubble was shown.
71 // true if some handling was performed. 85 virtual bool ShowBubble(const ui::Event& event);
72 virtual bool OnActivate(const ui::Event& event); 86
87 // Returns true if the bubble anchored to the icon is shown. This is to
88 // prevent the bubble from reshowing on a mouse release.
89 virtual bool IsBubbleShown() const;
73 90
74 // views::InkDropHostView: 91 // views::InkDropHostView:
75 gfx::Size GetPreferredSize() const override; 92 gfx::Size GetPreferredSize() const override;
76 void Layout() override; 93 void Layout() override;
94 bool OnMousePressed(const ui::MouseEvent& event) override;
77 bool OnKeyPressed(const ui::KeyEvent& event) override; 95 bool OnKeyPressed(const ui::KeyEvent& event) override;
78 bool OnKeyReleased(const ui::KeyEvent& event) override; 96 bool OnKeyReleased(const ui::KeyEvent& event) override;
79 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; 97 void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
98 void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
80 void OnNativeThemeChanged(const ui::NativeTheme* native_theme) override; 99 void OnNativeThemeChanged(const ui::NativeTheme* native_theme) override;
81 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; 100 void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
82 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; 101 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override;
102 std::unique_ptr<views::InkDrop> CreateInkDrop() override;
83 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() 103 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
84 const override; 104 const override;
105 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
85 SkColor GetInkDropBaseColor() const override; 106 SkColor GetInkDropBaseColor() const override;
86 107
108 // views::CustomButton:
109 bool IsTriggerableEvent(const ui::Event& event) override;
110 void OnClickCanceled(const ui::Event& event) override;
111
112 // views::WidgetObserver:
113 void OnWidgetDestroying(views::Widget* widget) override;
114 void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override;
115
87 const gfx::FontList& font_list() const { return label_->font_list(); } 116 const gfx::FontList& font_list() const { return label_->font_list(); }
88 117
89 SkColor GetParentBackgroundColor() const; 118 SkColor GetParentBackgroundColor() const;
90 119
91 gfx::Size GetSizeForLabelWidth(int label_width) const; 120 gfx::Size GetSizeForLabelWidth(int label_width) const;
92 121
122 // Returns the maximum size for the label width. The value ignores
123 // WidthMultiplier().
124 gfx::Size GetMaxSizeForLabelWidth(int label_width) const;
125
93 private: 126 private:
127 // A view that draws the separator.
128 class SeparatorView : public views::View {
129 public:
130 explicit SeparatorView(IconLabelBubbleView* owner);
131
132 // views::View:
133 void OnPaint(gfx::Canvas* canvas) override;
134 bool CanProcessEventsWithinSubtree() const override;
135
136 // Updates the opacity based on the ink drop's state.
137 void UpdateOpacity();
138
139 private:
140 // Weak.
141 IconLabelBubbleView* owner_;
142 };
sky 2017/05/05 23:40:20 DISALLOW...
spqchan 2017/05/10 19:22:11 Done.
143
94 // Amount of padding from the leading edge of the view to the leading edge of 144 // 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 145 // 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. 146 // is invisible) to the trailing edge of the view.
97 int GetOuterPadding() const; 147 int GetOuterPadding() const;
98 148
99 // Spacing between the image and the label. 149 // Spacing between the image and the label.
100 int GetInternalSpacing() const; 150 int GetInternalSpacing() const;
101 151
102 // Padding after the separator. 152 // Padding after the separator.
103 int GetPostSeparatorPadding() const; 153 int GetPostSeparatorPadding() const;
104 154
105 float GetScaleFactor() const; 155 float GetScaleFactor() const;
106 156
157 // The view has been activated by a user gesture such as spacebar.
158 // Returns true if some handling was performed.
159 bool OnActivate(const ui::Event& event);
160
107 // views::View: 161 // views::View:
108 const char* GetClassName() const override; 162 const char* GetClassName() const override;
109 void OnPaint(gfx::Canvas* canvas) override;
110 163
111 // The contents of the bubble. 164 // The contents of the bubble.
112 views::ImageView* image_; 165 views::ImageView* image_;
113 views::Label* label_; 166 views::Label* label_;
167 views::InkDropContainerView* ink_drop_container_;
168 std::unique_ptr<SeparatorView> separator_view_;
114 169
115 // The padding of the element that will be displayed after |this|. This value 170 // 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 171 // is relevant for calculating the amount of space to reserve after the
117 // separator. 172 // separator.
118 int next_element_interior_padding_ = 0; 173 int next_element_interior_padding_ = 0;
119 174
175 // This is used to check if the bubble was showing in the last mouse press
176 // event. If this is true then the IsTriggerableEvent() will return false to
177 // prevent the bubble from reshowing. This flag is necessary because the
178 // bubble gets dismissed before the button handles the mouse release event.
179 bool suppress_button_release_;
180
120 DISALLOW_COPY_AND_ASSIGN(IconLabelBubbleView); 181 DISALLOW_COPY_AND_ASSIGN(IconLabelBubbleView);
121 }; 182 };
122 183
123 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_ 184 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698