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

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: Refactored Created 3 years, 9 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"
15 #include "ui/views/controls/label.h" 16 #include "ui/views/controls/label.h"
17 #include "ui/views/widget/widget_observer.h"
16 18
17 namespace gfx { 19 namespace gfx {
18 class Canvas;
19 class FontList; 20 class FontList;
20 class ImageSkia; 21 class ImageSkia;
21 } 22 }
22 23
23 namespace views { 24 namespace views {
24 class ImageView; 25 class ImageView;
25 class Label; 26 class InkDropContainerView;
26 } 27 }
27 28
28 // View used to draw a bubble, containing an icon and a label. We use this as a 29 // 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), 30 // base for the classes that handle the location icon (including the EV bubble),
30 // tab-to-search UI, and content settings. 31 // tab-to-search UI, and content settings.
31 class IconLabelBubbleView : public views::InkDropHostView { 32 class IconLabelBubbleView : public views::InkDropHostView,
33 public views::InkDropObserver,
34 public views::WidgetObserver {
32 public: 35 public:
33 static constexpr int kTrailingPaddingPreMd = 2; 36 static constexpr int kTrailingPaddingPreMd = 2;
34 37
35 IconLabelBubbleView(const gfx::FontList& font_list, bool elide_in_middle); 38 IconLabelBubbleView(const gfx::FontList& font_list, bool elide_in_middle);
36 ~IconLabelBubbleView() override; 39 ~IconLabelBubbleView() override;
37 40
41 // InkDropObserver:
42 void AnimationStarted() override;
43
38 void SetLabel(const base::string16& label); 44 void SetLabel(const base::string16& label);
39 void SetImage(const gfx::ImageSkia& image); 45 void SetImage(const gfx::ImageSkia& image);
40 46
41 const views::ImageView* GetImageView() const { return image_; } 47 const views::ImageView* GetImageView() const { return image_; }
42 views::ImageView* GetImageView() { return image_; } 48 views::ImageView* GetImageView() { return image_; }
43 49
44 protected: 50 protected:
45 static constexpr int kOpenTimeMS = 150; 51 static constexpr int kOpenTimeMS = 150;
46 52
47 views::ImageView* image() { return image_; } 53 views::ImageView* image() { return image_; }
(...skipping 16 matching lines...) Expand all
64 // full-width view and can be used to animate the width of the view. 70 // full-width view and can be used to animate the width of the view.
65 virtual double WidthMultiplier() const; 71 virtual double WidthMultiplier() const;
66 72
67 // Returns true when animation is in progress and is shrinking. 73 // Returns true when animation is in progress and is shrinking.
68 virtual bool IsShrinking() const; 74 virtual bool IsShrinking() const;
69 75
70 // The view has been activated by a user gesture such as spacebar. Returns 76 // The view has been activated by a user gesture such as spacebar. Returns
71 // true if some handling was performed. 77 // true if some handling was performed.
72 virtual bool OnActivate(const ui::Event& event); 78 virtual bool OnActivate(const ui::Event& event);
73 79
80 // Returns true if the bubble anchored to the icon is shown. This is to
81 // prevent the bubble from reshowing on a mouse release.
82 virtual bool IsBubbleShown() const;
83
84 // Returns true if the user can click on the icon.
85 virtual bool CanClick() const;
86
74 // views::InkDropHostView: 87 // views::InkDropHostView:
75 gfx::Size GetPreferredSize() const override; 88 gfx::Size GetPreferredSize() const override;
76 void Layout() override; 89 void Layout() override;
90 bool OnMousePressed(const ui::MouseEvent& event) override;
91 void OnMouseReleased(const ui::MouseEvent& event) override;
77 bool OnKeyPressed(const ui::KeyEvent& event) override; 92 bool OnKeyPressed(const ui::KeyEvent& event) override;
78 bool OnKeyReleased(const ui::KeyEvent& event) override; 93 bool OnKeyReleased(const ui::KeyEvent& event) override;
79 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; 94 void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
80 void OnNativeThemeChanged(const ui::NativeTheme* native_theme) override; 95 void OnNativeThemeChanged(const ui::NativeTheme* native_theme) override;
81 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; 96 void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
82 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; 97 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override;
98 std::unique_ptr<views::InkDrop> CreateInkDrop() override;
83 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() 99 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
84 const override; 100 const override;
101 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
85 SkColor GetInkDropBaseColor() const override; 102 SkColor GetInkDropBaseColor() const override;
86 103
104 // views::WidgetObserver:
105 void OnWidgetDestroying(views::Widget* widget) override;
106 void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override;
107
87 const gfx::FontList& font_list() const { return label_->font_list(); } 108 const gfx::FontList& font_list() const { return label_->font_list(); }
88 109
89 SkColor GetParentBackgroundColor() const; 110 SkColor GetParentBackgroundColor() const;
90 111
91 gfx::Size GetSizeForLabelWidth(int label_width) const; 112 gfx::Size GetSizeForLabelWidth(int label_width) const;
92 113
93 private: 114 private:
115 // A view that draws the separator.
116 class SeparatorView : public views::View {
117 public:
118 explicit SeparatorView(IconLabelBubbleView* owner);
119
120 // View:
121 void OnPaint(gfx::Canvas* canvas) override;
122 bool CanProcessEventsWithinSubtree() const override;
123
124 // Updates the opacity based on the ink drop's state.
125 void UpdateOpacity();
126
127 private:
128 // Weak.
129 IconLabelBubbleView* owner_;
130 };
131
94 // Amount of padding from the leading edge of the view to the leading edge of 132 // 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 133 // 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. 134 // is invisible) to the trailing edge of the view.
97 int GetOuterPadding() const; 135 int GetOuterPadding() const;
98 136
99 // Spacing between the image and the label. 137 // Spacing between the image and the label.
100 int GetInternalSpacing() const; 138 int GetInternalSpacing() const;
101 139
102 // Padding after the separator. 140 // Padding after the separator.
103 int GetPostSeparatorPadding() const; 141 int GetPostSeparatorPadding() const;
104 142
105 float GetScaleFactor() const; 143 float GetScaleFactor() const;
106 144
107 // views::View: 145 // views::View:
108 const char* GetClassName() const override; 146 const char* GetClassName() const override;
109 void OnPaint(gfx::Canvas* canvas) override;
110 147
111 // The contents of the bubble. 148 // The contents of the bubble.
112 views::ImageView* image_; 149 views::ImageView* image_;
113 views::Label* label_; 150 views::Label* label_;
151 views::InkDropContainerView* ink_drop_container_;
152 std::unique_ptr<SeparatorView> separator_view_;
114 153
115 // The padding of the element that will be displayed after |this|. This value 154 // 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 155 // is relevant for calculating the amount of space to reserve after the
117 // separator. 156 // separator.
118 int next_element_interior_padding_ = 0; 157 int next_element_interior_padding_ = 0;
119 158
159 // This is used to check if the bubble was showing during the mouse pressed
160 // event. If this is true then the mouse released event is ignored to prevent
161 // the bubble from reshowing.
162 bool suppress_mouse_released_action_;
163
120 DISALLOW_COPY_AND_ASSIGN(IconLabelBubbleView); 164 DISALLOW_COPY_AND_ASSIGN(IconLabelBubbleView);
121 }; 165 };
122 166
123 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_ 167 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698