Chromium Code Reviews| 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/compositor/layer_animation_observer.h" | |
| 12 #include "ui/gfx/geometry/insets.h" | 13 #include "ui/gfx/geometry/insets.h" |
| 13 #include "ui/gfx/geometry/size.h" | 14 #include "ui/gfx/geometry/size.h" |
| 14 #include "ui/views/animation/ink_drop_host_view.h" | 15 #include "ui/views/animation/ink_drop_host_view.h" |
| 16 #include "ui/views/animation/ink_drop_observer.h" | |
| 17 #include "ui/views/controls/button/custom_button.h" | |
| 15 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/label.h" |
| 19 #include "ui/views/widget/widget_observer.h" | |
| 16 | 20 |
| 17 namespace gfx { | 21 namespace gfx { |
| 18 class Canvas; | |
| 19 class FontList; | 22 class FontList; |
| 20 class ImageSkia; | 23 class ImageSkia; |
| 21 } | 24 } |
| 22 | 25 |
| 23 namespace views { | 26 namespace views { |
| 24 class ImageView; | 27 class ImageView; |
| 25 class Label; | 28 class InkDropContainerView; |
| 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::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 | |
| 38 void SetLabel(const base::string16& label); | 46 void SetLabel(const base::string16& label); |
| 39 void SetImage(const gfx::ImageSkia& image); | 47 void SetImage(const gfx::ImageSkia& image); |
| 40 | 48 |
| 41 const views::ImageView* GetImageView() const { return image_; } | 49 const views::ImageView* GetImageView() const { return image_; } |
| 42 views::ImageView* GetImageView() { return image_; } | 50 views::ImageView* GetImageView() { return image_; } |
| 43 | 51 |
| 44 protected: | 52 protected: |
| 45 static constexpr int kOpenTimeMS = 150; | 53 static constexpr int kOpenTimeMS = 150; |
| 46 | 54 |
| 47 views::ImageView* image() { return image_; } | 55 views::ImageView* image() { return image_; } |
| 48 const views::ImageView* image() const { return image_; } | 56 const views::ImageView* image() const { return image_; } |
| 49 views::Label* label() { return label_; } | 57 views::Label* label() { return label_; } |
| 50 const views::Label* label() const { return label_; } | 58 const views::Label* label() const { return label_; } |
| 59 const views::InkDropContainerView* ink_drop_container() const { | |
| 60 return ink_drop_container_; | |
| 61 } | |
| 51 | 62 |
| 52 void set_next_element_interior_padding(int padding) { | 63 void set_next_element_interior_padding(int padding) { |
| 53 next_element_interior_padding_ = padding; | 64 next_element_interior_padding_ = padding; |
| 54 } | 65 } |
| 55 | 66 |
| 56 // Gets the color for displaying text. | 67 // Gets the color for displaying text. |
| 57 virtual SkColor GetTextColor() const = 0; | 68 virtual SkColor GetTextColor() const = 0; |
| 58 | 69 |
| 59 // Returns true when the label should be visible. | 70 // Returns true when the label should be visible. |
| 60 virtual bool ShouldShowLabel() const; | 71 virtual bool ShouldShowLabel() const; |
| 61 | 72 |
| 62 // Returns a multiplier used to calculate the actual width of the view based | 73 // 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 | 74 // 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. | 75 // full-width view and can be used to animate the width of the view. |
| 65 virtual double WidthMultiplier() const; | 76 virtual double WidthMultiplier() const; |
| 66 | 77 |
| 67 // Returns true when animation is in progress and is shrinking. | 78 // Returns true when animation is in progress and is shrinking. |
| 68 virtual bool IsShrinking() const; | 79 virtual bool IsShrinking() const; |
| 69 | 80 |
| 70 // The view has been activated by a user gesture such as spacebar. Returns | 81 // Returns true if a bubble was shown. |
| 71 // true if some handling was performed. | 82 virtual bool ShowBubble(const ui::Event& event); |
| 72 virtual bool OnActivate(const ui::Event& event); | 83 |
| 84 // Returns true if the bubble anchored to the icon is shown. This is to | |
| 85 // prevent the bubble from reshowing on a mouse release. | |
| 86 virtual bool IsBubbleShown() const; | |
|
sky
2017/05/12 13:11:48
IsBubbleShowing()
spqchan
2017/05/18 01:13:05
Done.
| |
| 73 | 87 |
| 74 // views::InkDropHostView: | 88 // views::InkDropHostView: |
| 75 gfx::Size GetPreferredSize() const override; | 89 gfx::Size GetPreferredSize() const override; |
| 76 void Layout() override; | 90 void Layout() override; |
| 91 bool OnMousePressed(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; |
| 95 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | |
| 80 void OnNativeThemeChanged(const ui::NativeTheme* native_theme) override; | 96 void OnNativeThemeChanged(const ui::NativeTheme* native_theme) override; |
| 81 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; | 97 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 82 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; | 98 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 99 std::unique_ptr<views::InkDrop> CreateInkDrop() override; | |
| 83 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() | 100 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() |
| 84 const override; | 101 const override; |
| 102 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; | |
| 85 SkColor GetInkDropBaseColor() const override; | 103 SkColor GetInkDropBaseColor() const override; |
| 86 | 104 |
| 105 // views::CustomButton: | |
| 106 bool IsTriggerableEvent(const ui::Event& event) override; | |
| 107 bool ShouldUpdateInkDropOnClickCanceled() const override; | |
| 108 void NotifyClick(const ui::Event& event) override; | |
| 109 | |
| 110 // views::WidgetObserver: | |
| 111 void OnWidgetDestroying(views::Widget* widget) override; | |
| 112 void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override; | |
| 113 | |
| 87 const gfx::FontList& font_list() const { return label_->font_list(); } | 114 const gfx::FontList& font_list() const { return label_->font_list(); } |
| 88 | 115 |
| 89 SkColor GetParentBackgroundColor() const; | 116 SkColor GetParentBackgroundColor() const; |
| 90 | 117 |
| 91 gfx::Size GetSizeForLabelWidth(int label_width) const; | 118 gfx::Size GetSizeForLabelWidth(int label_width) const; |
| 92 | 119 |
| 120 // Returns the maximum size for the label width. The value ignores | |
| 121 // WidthMultiplier(). | |
| 122 gfx::Size GetMaxSizeForLabelWidth(int label_width) const; | |
| 123 | |
| 93 private: | 124 private: |
| 125 // A view that draws the separator. | |
| 126 class SeparatorView : public views::View, | |
| 127 public ui::ImplicitAnimationObserver { | |
| 128 public: | |
| 129 explicit SeparatorView(IconLabelBubbleView* owner); | |
| 130 | |
| 131 // views::View: | |
| 132 void OnPaint(gfx::Canvas* canvas) override; | |
| 133 bool CanProcessEventsWithinSubtree() const override; | |
| 134 | |
| 135 // ui::ImplicitAnimationObserver: | |
| 136 void OnImplicitAnimationsCompleted() override; | |
| 137 | |
| 138 // Updates the opacity based on the ink drop's state. | |
| 139 void UpdateOpacity(); | |
| 140 | |
| 141 private: | |
| 142 // Weak. | |
| 143 IconLabelBubbleView* owner_; | |
| 144 | |
| 145 DISALLOW_COPY_AND_ASSIGN(SeparatorView); | |
| 146 }; | |
| 147 | |
| 94 // Amount of padding from the leading edge of the view to the leading edge of | 148 // 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 | 149 // 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. | 150 // is invisible) to the trailing edge of the view. |
| 97 int GetOuterPadding() const; | 151 int GetOuterPadding() const; |
| 98 | 152 |
| 99 // Spacing between the image and the label. | 153 // Spacing between the image and the label. |
| 100 int GetInternalSpacing() const; | 154 int GetInternalSpacing() const; |
| 101 | 155 |
| 102 // Padding after the separator. | 156 // Padding after the separator. |
| 103 int GetPostSeparatorPadding() const; | 157 int GetPostSeparatorPadding() const; |
| 104 | 158 |
| 105 float GetScaleFactor() const; | 159 float GetScaleFactor() const; |
| 106 | 160 |
| 161 // The view has been activated by a user gesture such as spacebar. | |
| 162 // Returns true if some handling was performed. | |
| 163 bool OnActivate(const ui::Event& event); | |
| 164 | |
| 107 // views::View: | 165 // views::View: |
| 108 const char* GetClassName() const override; | 166 const char* GetClassName() const override; |
| 109 void OnPaint(gfx::Canvas* canvas) override; | |
| 110 | 167 |
| 111 // The contents of the bubble. | 168 // The contents of the bubble. |
| 112 views::ImageView* image_; | 169 views::ImageView* image_; |
| 113 views::Label* label_; | 170 views::Label* label_; |
| 171 views::InkDropContainerView* ink_drop_container_; | |
| 172 std::unique_ptr<SeparatorView> separator_view_; | |
|
sky
2017/05/12 13:11:48
Why do you use a unique_ptr for SeparatorView but
spqchan
2017/05/18 01:13:05
Removed unique_ptr
| |
| 114 | 173 |
| 115 // The padding of the element that will be displayed after |this|. This value | 174 // 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 | 175 // is relevant for calculating the amount of space to reserve after the |
| 117 // separator. | 176 // separator. |
| 118 int next_element_interior_padding_ = 0; | 177 int next_element_interior_padding_ = 0; |
| 119 | 178 |
| 179 // This is used to check if the bubble was showing in the last mouse press | |
| 180 // event. If this is true then the IsTriggerableEvent() will return false to | |
|
sky
2017/05/12 13:11:48
Remove 'the' or add 'function' before 'will'.
spqchan
2017/05/18 01:13:05
Done.
| |
| 181 // prevent the bubble from reshowing. This flag is necessary because the | |
| 182 // bubble gets dismissed before the button handles the mouse release event. | |
| 183 bool suppress_button_release_; | |
|
sky
2017/05/12 13:11:48
Is there test coverage of this? By that I mean a t
spqchan
2017/05/18 01:13:05
Done. Added in the unit test
| |
| 184 | |
| 120 DISALLOW_COPY_AND_ASSIGN(IconLabelBubbleView); | 185 DISALLOW_COPY_AND_ASSIGN(IconLabelBubbleView); |
| 121 }; | 186 }; |
| 122 | 187 |
| 123 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_ | 188 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_ |
| OLD | NEW |