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

Side by Side Diff: chrome/browser/ui/views/find_bar_view.cc

Issue 1396903003: Added the ripple effect animation to find bar buttons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from patch set 1. Created 5 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/ui/views/find_bar_view.h" 5 #include "chrome/browser/ui/views/find_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 18 matching lines...) Expand all
29 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
30 #include "ui/base/theme_provider.h" 30 #include "ui/base/theme_provider.h"
31 #include "ui/events/event.h" 31 #include "ui/events/event.h"
32 #include "ui/gfx/canvas.h" 32 #include "ui/gfx/canvas.h"
33 #include "ui/gfx/color_palette.h" 33 #include "ui/gfx/color_palette.h"
34 #include "ui/gfx/paint_vector_icon.h" 34 #include "ui/gfx/paint_vector_icon.h"
35 #include "ui/gfx/vector_icons_public.h" 35 #include "ui/gfx/vector_icons_public.h"
36 #include "ui/native_theme/common_theme.h" 36 #include "ui/native_theme/common_theme.h"
37 #include "ui/native_theme/native_theme.h" 37 #include "ui/native_theme/native_theme.h"
38 #include "ui/resources/grit/ui_resources.h" 38 #include "ui/resources/grit/ui_resources.h"
39 #include "ui/views/animation/ink_drop_animation_controller.h"
40 #include "ui/views/animation/ink_drop_animation_controller_factory.h"
41 #include "ui/views/animation/ink_drop_host.h"
39 #include "ui/views/background.h" 42 #include "ui/views/background.h"
40 #include "ui/views/border.h" 43 #include "ui/views/border.h"
41 #include "ui/views/bubble/bubble_border.h" 44 #include "ui/views/bubble/bubble_border.h"
42 #include "ui/views/controls/button/image_button.h" 45 #include "ui/views/controls/button/image_button.h"
43 #include "ui/views/controls/label.h" 46 #include "ui/views/controls/label.h"
44 #include "ui/views/controls/separator.h" 47 #include "ui/views/controls/separator.h"
45 #include "ui/views/layout/box_layout.h" 48 #include "ui/views/layout/box_layout.h"
46 #include "ui/views/painter.h" 49 #include "ui/views/painter.h"
47 #include "ui/views/view_targeter.h" 50 #include "ui/views/view_targeter.h"
48 #include "ui/views/widget/widget.h" 51 #include "ui/views/widget/widget.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // The color of the match count label for Material Design. 93 // The color of the match count label for Material Design.
91 const SkColor kMatchTextColorMD = SkColorSetRGB(0x96, 0x96, 0x96); 94 const SkColor kMatchTextColorMD = SkColorSetRGB(0x96, 0x96, 0x96);
92 95
93 // Color of the vertical separator between match count and buttons. (MD only.) 96 // Color of the vertical separator between match count and buttons. (MD only.)
94 const SkColor kSeparatorColor = SkColorSetARGB(0x26, 0, 0, 0); 97 const SkColor kSeparatorColor = SkColorSetARGB(0x26, 0, 0, 0);
95 98
96 // The default number of average characters that the text box will be. This 99 // The default number of average characters that the text box will be. This
97 // number brings the width on a "regular fonts" system to about 300px. 100 // number brings the width on a "regular fonts" system to about 300px.
98 const int kDefaultCharWidth = 43; 101 const int kDefaultCharWidth = 43;
99 102
103 class FindBarButton : public views::ImageButton, public views::InkDropHost {
104 public:
105 FindBarButton(views::ButtonListener* listener)
Peter Kasting 2015/10/09 22:09:30 Do not inline any of these methods. Define these
Hadi 2015/10/13 18:48:17 Done.
106 : views::ImageButton(listener),
107 ink_drop_animation_controller_(
108 views::InkDropAnimationControllerFactory::
109 CreateInkDropAnimationController(this)) {
110 // Sizes for ink drop animation.
111 const int kInkDropLargeSize = 24;
112 const int kInkDropLargeCornerRadius = 4;
113 const int kInkDropSmallSize = 18;
114 const int kInkDropSmallCornerRadius = 2;
115
116 ink_drop_animation_controller_->SetInkDropSize(
117 gfx::Size(kInkDropLargeSize, kInkDropLargeSize),
118 kInkDropLargeCornerRadius,
119 gfx::Size(kInkDropSmallSize, kInkDropSmallSize),
120 kInkDropSmallCornerRadius);
121 }
122
123 ~FindBarButton() override {}
124
125 private:
126 void Layout() override {
127 ImageButton::Layout();
128
129 ink_drop_animation_controller_->SetInkDropCenter(
130 GetLocalBounds().CenterPoint());
131 }
132
133 void AddInkDropLayer(ui::Layer* ink_drop_layer) override {
134 SetPaintToLayer(true);
135 SetFillsBoundsOpaquely(false);
136 layer()->Add(ink_drop_layer);
137 layer()->StackAtBottom(ink_drop_layer);
138 }
139
140 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override {
141 layer()->Remove(ink_drop_layer);
142 SetFillsBoundsOpaquely(true);
143 SetPaintToLayer(false);
144 }
145
146 bool OnMousePressed(const ui::MouseEvent& event) override {
147 if (IsTriggerableEvent(event)) {
148 ink_drop_animation_controller_->AnimateToState(
149 views::InkDropState::ACTION_PENDING);
150 }
151
152 return ImageButton::OnMousePressed(event);
153 }
154
155 void OnGestureEvent(ui::GestureEvent* event) override {
156 ImageButton::OnGestureEvent(event);
Peter Kasting 2015/10/09 22:09:30 Why is it that for mouse pressed we do our ink dro
Hadi 2015/10/13 18:48:17 Done.
157
158 views::InkDropState ink_drop_state = views::InkDropState::HIDDEN;
159 switch (event->type()) {
160 case ui::ET_GESTURE_TAP_DOWN:
161 ink_drop_state = views::InkDropState::ACTION_PENDING;
Peter Kasting 2015/10/09 22:09:30 It kinda surprises me we haven't needed a mapping
Hadi 2015/10/13 18:48:17 bruthig is going to comment on this.
bruthig 2015/10/13 18:54:29 Ideally we would be able to capture this behavior
162 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so
163 // that subsequent events for the gesture are sent to |this|.
164 event->SetHandled();
165 break;
166 case ui::ET_GESTURE_LONG_PRESS:
167 ink_drop_state = views::InkDropState::SLOW_ACTION_PENDING;
168 break;
169 case ui::ET_GESTURE_TAP:
170 ink_drop_state = views::InkDropState::QUICK_ACTION;
171 break;
172 case ui::ET_GESTURE_LONG_TAP:
173 ink_drop_state = views::InkDropState::SLOW_ACTION;
174 break;
175 case ui::ET_GESTURE_END:
176 case ui::ET_GESTURE_TAP_CANCEL:
177 ink_drop_state = views::InkDropState::HIDDEN;
178 break;
179 default:
180 return;
181 }
182 ink_drop_animation_controller_->AnimateToState(ink_drop_state);
183 }
184
185 void OnMouseReleased(const ui::MouseEvent& event) override {
186 ImageButton::OnMouseReleased(event);
187
188 if (!HitTestPoint(event.location()))
189 ink_drop_animation_controller_->AnimateToState(
190 views::InkDropState::HIDDEN);
191 }
192
193 void NotifyClick(const ui::Event& event) override {
194 ImageButton::NotifyClick(event);
195 ink_drop_animation_controller_->AnimateToState(
196 views::InkDropState::QUICK_ACTION);
197 }
198
199 // Animation controller for the ink drop ripple effect.
200 scoped_ptr<views::InkDropAnimationController> ink_drop_animation_controller_;
201 };
Peter Kasting 2015/10/09 22:09:30 DISALLOW_COPY_AND_ASSIGN?
Hadi 2015/10/13 18:48:17 Done.
202
100 // The match count label is like a normal label, but can process events (which 203 // The match count label is like a normal label, but can process events (which
101 // makes it easier to forward events to the text input --- see 204 // makes it easier to forward events to the text input --- see
102 // FindBarView::TargetForRect). 205 // FindBarView::TargetForRect).
103 class MatchCountLabel : public views::Label { 206 class MatchCountLabel : public views::Label {
104 public: 207 public:
105 MatchCountLabel() {} 208 MatchCountLabel() {}
106 ~MatchCountLabel() override {} 209 ~MatchCountLabel() override {}
107 210
108 // views::Label overrides: 211 // views::Label overrides:
109 bool CanProcessEventsWithinSubtree() const override { return true; } 212 bool CanProcessEventsWithinSubtree() const override { return true; }
(...skipping 16 matching lines...) Expand all
126 find_next_button_(NULL), 229 find_next_button_(NULL),
127 close_button_(NULL) { 230 close_button_(NULL) {
128 find_text_ = new views::Textfield; 231 find_text_ = new views::Textfield;
129 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); 232 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD);
130 find_text_->set_default_width_in_chars(kDefaultCharWidth); 233 find_text_->set_default_width_in_chars(kDefaultCharWidth);
131 find_text_->set_controller(this); 234 find_text_->set_controller(this);
132 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); 235 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND));
133 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); 236 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF);
134 AddChildView(find_text_); 237 AddChildView(find_text_);
135 238
136 find_previous_button_ = new views::ImageButton(this); 239 find_previous_button_ = new FindBarButton(this);
137 find_previous_button_->set_tag(FIND_PREVIOUS_TAG); 240 find_previous_button_->set_tag(FIND_PREVIOUS_TAG);
138 find_previous_button_->SetFocusable(true); 241 find_previous_button_->SetFocusable(true);
139 find_previous_button_->SetTooltipText( 242 find_previous_button_->SetTooltipText(
140 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP)); 243 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP));
141 find_previous_button_->SetAccessibleName( 244 find_previous_button_->SetAccessibleName(
142 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS)); 245 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS));
143 AddChildView(find_previous_button_); 246 AddChildView(find_previous_button_);
144 247
145 find_next_button_ = new views::ImageButton(this); 248 find_next_button_ = new FindBarButton(this);
146 find_next_button_->set_tag(FIND_NEXT_TAG); 249 find_next_button_->set_tag(FIND_NEXT_TAG);
147 find_next_button_->SetFocusable(true); 250 find_next_button_->SetFocusable(true);
148 find_next_button_->SetTooltipText( 251 find_next_button_->SetTooltipText(
149 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP)); 252 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP));
150 find_next_button_->SetAccessibleName( 253 find_next_button_->SetAccessibleName(
151 l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT)); 254 l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT));
152 AddChildView(find_next_button_); 255 AddChildView(find_next_button_);
153 256
154 close_button_ = new views::ImageButton(this); 257 close_button_ = new FindBarButton(this);
155 close_button_->set_tag(CLOSE_TAG); 258 close_button_->set_tag(CLOSE_TAG);
156 close_button_->SetFocusable(true); 259 close_button_->SetFocusable(true);
157 close_button_->SetTooltipText( 260 close_button_->SetTooltipText(
158 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP)); 261 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP));
159 close_button_->SetAccessibleName( 262 close_button_->SetAccessibleName(
160 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); 263 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE));
161 close_button_->SetAnimationDuration(0); 264 close_button_->SetAnimationDuration(0);
162 AddChildView(close_button_); 265 AddChildView(close_button_);
163 266
164 EnableCanvasFlippingForRTLUI(true); 267 EnableCanvasFlippingForRTLUI(true);
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 void FindBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { 757 void FindBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
655 if (!ui::MaterialDesignController::IsModeMaterial()) 758 if (!ui::MaterialDesignController::IsModeMaterial())
656 return; 759 return;
657 760
658 SkColor color = 761 SkColor color =
659 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); 762 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground);
660 set_background(views::Background::CreateSolidBackground(color)); 763 set_background(views::Background::CreateSolidBackground(color));
661 match_count_text_->SetBackgroundColor(color); 764 match_count_text_->SetBackgroundColor(color);
662 match_count_text_->SetEnabledColor(kMatchTextColorMD); 765 match_count_text_->SetEnabledColor(kMatchTextColorMD);
663 } 766 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698