Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_BUBBLE_ICON_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_BUBBLE_ICON_VIEW_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_BUBBLE_ICON_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_BUBBLE_ICON_VIEW_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 9 #include "ui/gfx/image/image_skia.h" | 10 #include "ui/gfx/image/image_skia.h" |
| 10 #include "ui/gfx/vector_icons_public.h" | 11 #include "ui/gfx/vector_icons_public.h" |
| 12 #include "ui/views/animation/ink_drop_host.h" | |
| 11 #include "ui/views/controls/image_view.h" | 13 #include "ui/views/controls/image_view.h" |
| 14 #include "ui/views/widget/widget_observer_view.h" | |
| 12 | 15 |
| 13 class CommandUpdater; | 16 class CommandUpdater; |
| 14 | 17 |
| 15 namespace gfx { | 18 namespace gfx { |
| 16 enum class VectorIconId; | 19 enum class VectorIconId; |
| 17 } | 20 } |
| 18 | 21 |
| 19 namespace views { | 22 namespace views { |
| 20 class BubbleDelegateView; | 23 class BubbleDelegateView; |
| 24 class InkDropDelegate; | |
| 21 } | 25 } |
| 22 | 26 |
| 23 // Represents an icon on the omnibox that shows a bubble when clicked. | 27 // Represents an icon on the omnibox that shows a bubble when clicked. |
| 24 class BubbleIconView : public views::ImageView { | 28 class BubbleIconView : public views::WidgetObserverView, |
| 29 public views::InkDropHost { | |
| 25 protected: | 30 protected: |
| 26 enum ExecuteSource { | 31 enum ExecuteSource { |
| 27 EXECUTE_SOURCE_MOUSE, | 32 EXECUTE_SOURCE_MOUSE, |
| 28 EXECUTE_SOURCE_KEYBOARD, | 33 EXECUTE_SOURCE_KEYBOARD, |
| 29 EXECUTE_SOURCE_GESTURE, | 34 EXECUTE_SOURCE_GESTURE, |
| 30 }; | 35 }; |
| 31 | 36 |
| 32 BubbleIconView(CommandUpdater* command_updater, int command_id); | 37 BubbleIconView(CommandUpdater* command_updater, int command_id); |
| 33 ~BubbleIconView() override; | 38 ~BubbleIconView() override; |
| 34 | 39 |
| 35 // Returns true if a related bubble is showing. | 40 // Returns true if a related bubble is showing. |
| 36 bool IsBubbleShowing() const; | 41 bool IsBubbleShowing() const; |
| 37 | 42 |
| 43 // Sets the image that should be displayed in |image_|. | |
| 44 void SetImage(const gfx::ImageSkia* image_skia); | |
| 45 | |
| 46 // Returns the image currently displayed which can be empty if not set. | |
|
Peter Kasting
2016/01/28 00:22:08
Nit: Comma after "displayed"
varkha
2016/01/28 00:32:50
Done.
| |
| 47 // The returned image is owned by |image_|. | |
| 48 const gfx::ImageSkia& GetImage() const; | |
| 49 | |
| 50 // Sets the tooltip text. | |
| 51 void SetTooltipText(const base::string16& tooltip); | |
| 52 | |
| 38 // Invoked prior to executing the command. | 53 // Invoked prior to executing the command. |
| 39 virtual void OnExecuting(ExecuteSource execute_source) = 0; | 54 virtual void OnExecuting(ExecuteSource execute_source) = 0; |
| 40 | 55 |
| 41 // views::ImageView: | 56 // views::View: |
| 42 void GetAccessibleState(ui::AXViewState* state) override; | 57 void GetAccessibleState(ui::AXViewState* state) override; |
| 43 bool GetTooltipText(const gfx::Point& p, base::string16* tooltip) const | 58 bool GetTooltipText(const gfx::Point& p, base::string16* tooltip) const |
| 44 override; | 59 override; |
| 60 gfx::Size GetPreferredSize() const override; | |
| 61 void Layout() override; | |
| 45 bool OnMousePressed(const ui::MouseEvent& event) override; | 62 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 46 void OnMouseReleased(const ui::MouseEvent& event) override; | 63 void OnMouseReleased(const ui::MouseEvent& event) override; |
| 47 bool OnKeyPressed(const ui::KeyEvent& event) override; | 64 bool OnKeyPressed(const ui::KeyEvent& event) override; |
| 48 void ViewHierarchyChanged( | 65 void ViewHierarchyChanged( |
| 49 const ViewHierarchyChangedDetails& details) override; | 66 const ViewHierarchyChangedDetails& details) override; |
| 50 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 67 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
| 51 | 68 |
| 52 // ui::EventHandler: | 69 // ui::EventHandler: |
| 53 void OnGestureEvent(ui::GestureEvent* event) override; | 70 void OnGestureEvent(ui::GestureEvent* event) override; |
| 54 | 71 |
| 72 // views::InkDropHost: | |
| 73 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; | |
| 74 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; | |
| 75 | |
| 76 // views::WidgetObserver: | |
| 77 void OnWidgetVisibilityChanged(views::Widget* widget, | |
| 78 bool visible) override; | |
| 79 | |
| 55 protected: | 80 protected: |
| 56 // Calls OnExecuting and runs |command_id_| with a valid |command_updater_|. | 81 // Calls OnExecuting and runs |command_id_| with a valid |command_updater_|. |
| 57 virtual void ExecuteCommand(ExecuteSource source); | 82 virtual void ExecuteCommand(ExecuteSource source); |
| 58 | 83 |
| 59 // Returns the bubble instance for the icon. | 84 // Returns the bubble instance for the icon. |
| 60 virtual views::BubbleDelegateView* GetBubble() const = 0; | 85 virtual views::BubbleDelegateView* GetBubble() const = 0; |
| 61 | 86 |
| 62 // Gets the given vector icon in the correct color and size based on |active| | 87 // Gets the given vector icon in the correct color and size based on |active| |
| 63 // and whether Chrome's in material design mode. | 88 // and whether Chrome's in material design mode. |
| 64 virtual gfx::VectorIconId GetVectorIcon() const = 0; | 89 virtual gfx::VectorIconId GetVectorIcon() const; |
| 65 | 90 |
| 66 // Sets the image using a PNG from the resource bundle. Returns true if an | 91 // Sets the image using a PNG from the resource bundle. Returns true if an |
| 67 // image was set, or false if the icon should use a vector asset. This only | 92 // image was set, or false if the icon should use a vector asset. This only |
| 68 // exists for non-MD mode. TODO(estade): remove it. | 93 // exists for non-MD mode. TODO(estade): remove it. |
| 69 virtual bool SetRasterIcon(); | 94 virtual bool SetRasterIcon(); |
| 70 | 95 |
| 71 // views::View: | 96 // views::View: |
| 72 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | 97 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; |
| 73 | 98 |
| 99 // views::InkDropHost: | |
| 100 gfx::Point CalculateInkDropCenter() const override; | |
| 101 bool ShouldShowInkDropHover() const override; | |
| 102 | |
| 74 // Updates the icon after some state has changed. | 103 // Updates the icon after some state has changed. |
| 75 void UpdateIcon(); | 104 void UpdateIcon(); |
| 76 | 105 |
| 77 // Sets the active state of the icon. An active icon will be displayed in a | 106 // Sets the active state of the icon. An active icon will be displayed in a |
| 78 // "call to action" color. | 107 // "call to action" color. |
| 79 void SetActiveInternal(bool active); | 108 void SetActiveInternal(bool active); |
| 80 | 109 |
| 81 bool active() const { return active_; } | 110 bool active() const { return active_; } |
| 82 | 111 |
| 83 private: | 112 private: |
| 113 // The image shown in the button. | |
| 114 views::ImageView* image_; | |
| 115 | |
| 84 // The CommandUpdater for the Browser object that owns the location bar. | 116 // The CommandUpdater for the Browser object that owns the location bar. |
| 85 CommandUpdater* command_updater_; | 117 CommandUpdater* command_updater_; |
| 86 | 118 |
| 87 // The command ID executed when the user clicks this icon. | 119 // The command ID executed when the user clicks this icon. |
| 88 const int command_id_; | 120 const int command_id_; |
| 89 | 121 |
| 90 // The active state. The precise definition of "active" is unique to each | 122 // The active state. The precise definition of "active" is unique to each |
| 91 // subclass, but generally indicates that the associated feature is acting on | 123 // subclass, but generally indicates that the associated feature is acting on |
| 92 // the web page. | 124 // the web page. |
| 93 bool active_; | 125 bool active_; |
| 94 | 126 |
| 95 // This is used to check if the bookmark bubble was showing during the mouse | 127 // This is used to check if the bookmark bubble was showing during the mouse |
| 96 // pressed event. If this is true then the mouse released event is ignored to | 128 // pressed event. If this is true then the mouse released event is ignored to |
| 97 // prevent the bubble from reshowing. | 129 // prevent the bubble from reshowing. |
| 98 bool suppress_mouse_released_action_; | 130 bool suppress_mouse_released_action_; |
| 99 | 131 |
| 132 // Animation delegate for the ink drop ripple effect. | |
| 133 scoped_ptr<views::InkDropDelegate> ink_drop_delegate_; | |
| 134 | |
| 100 DISALLOW_COPY_AND_ASSIGN(BubbleIconView); | 135 DISALLOW_COPY_AND_ASSIGN(BubbleIconView); |
| 101 }; | 136 }; |
| 102 | 137 |
| 103 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_BUBBLE_ICON_VIEW_H_ | 138 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_BUBBLE_ICON_VIEW_H_ |
| OLD | NEW |