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

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

Issue 1518543002: Adds MD ink ripple animations to buttons within location bar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds MD ink ripple animations to buttons within location bar (reverted a bad change) Created 4 years, 10 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 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.
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 OnWidgetDestroying(views::Widget* widget) override;
78 void OnWidgetVisibilityChanged(views::Widget* widget,
79 bool visible) override;
80
81 // views::WidgetObserverView:
82 void ObserveWidget(views::Widget* widget) override;
83
55 protected: 84 protected:
56 // Calls OnExecuting and runs |command_id_| with a valid |command_updater_|. 85 // Calls OnExecuting and runs |command_id_| with a valid |command_updater_|.
57 virtual void ExecuteCommand(ExecuteSource source); 86 virtual void ExecuteCommand(ExecuteSource source);
58 87
59 // Returns the bubble instance for the icon. 88 // Returns the bubble instance for the icon.
60 virtual views::BubbleDelegateView* GetBubble() const = 0; 89 virtual views::BubbleDelegateView* GetBubble() const = 0;
61 90
62 // Gets the given vector icon in the correct color and size based on |active| 91 // Gets the given vector icon in the correct color and size based on |active|
63 // and whether Chrome's in material design mode. 92 // and whether Chrome's in material design mode.
64 virtual gfx::VectorIconId GetVectorIcon() const = 0; 93 virtual gfx::VectorIconId GetVectorIcon() const;
65 94
66 // Sets the image using a PNG from the resource bundle. Returns true if an 95 // 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 96 // 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. 97 // exists for non-MD mode. TODO(estade): remove it.
69 virtual bool SetRasterIcon(); 98 virtual bool SetRasterIcon();
70 99
71 // views::View: 100 // views::View:
72 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; 101 void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
73 102
103 // views::InkDropHost:
104 gfx::Point CalculateInkDropCenter() const override;
105 bool ShouldShowInkDropHover() const override;
106
74 // Updates the icon after some state has changed. 107 // Updates the icon after some state has changed.
75 void UpdateIcon(); 108 void UpdateIcon();
76 109
77 // Sets the active state of the icon. An active icon will be displayed in a 110 // Sets the active state of the icon. An active icon will be displayed in a
78 // "call to action" color. 111 // "call to action" color.
79 void SetActiveInternal(bool active); 112 void SetActiveInternal(bool active);
80 113
81 bool active() const { return active_; } 114 bool active() const { return active_; }
82 115
83 private: 116 private:
117 // The image shown in the button.
118 views::ImageView* image_;
119
84 // The CommandUpdater for the Browser object that owns the location bar. 120 // The CommandUpdater for the Browser object that owns the location bar.
85 CommandUpdater* command_updater_; 121 CommandUpdater* command_updater_;
86 122
87 // The command ID executed when the user clicks this icon. 123 // The command ID executed when the user clicks this icon.
88 const int command_id_; 124 const int command_id_;
89 125
90 // The active state. The precise definition of "active" is unique to each 126 // The active state. The precise definition of "active" is unique to each
91 // subclass, but generally indicates that the associated feature is acting on 127 // subclass, but generally indicates that the associated feature is acting on
92 // the web page. 128 // the web page.
93 bool active_; 129 bool active_;
94 130
95 // This is used to check if the bookmark bubble was showing during the mouse 131 // 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 132 // pressed event. If this is true then the mouse released event is ignored to
97 // prevent the bubble from reshowing. 133 // prevent the bubble from reshowing.
98 bool suppress_mouse_released_action_; 134 bool suppress_mouse_released_action_;
99 135
136 // Animation delegate for the ink drop ripple effect.
137 scoped_ptr<views::InkDropDelegate> ink_drop_delegate_;
138
100 DISALLOW_COPY_AND_ASSIGN(BubbleIconView); 139 DISALLOW_COPY_AND_ASSIGN(BubbleIconView);
101 }; 140 };
102 141
103 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_BUBBLE_ICON_VIEW_H_ 142 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_BUBBLE_ICON_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698