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