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

Side by Side Diff: chrome/browser/ui/views/location_bar/content_setting_image_view.cc

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 (added ContentSettingImageView) 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 (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/location_bar/content_setting_image_view.h" 5 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/themes/theme_properties.h" 8 #include "chrome/browser/themes/theme_properties.h"
9 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 9 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
10 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" 10 #include "chrome/browser/ui/content_settings/content_setting_image_model.h"
11 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" 11 #include "chrome/browser/ui/views/content_setting_bubble_contents.h"
12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
13 #include "grit/theme_resources.h" 13 #include "grit/theme_resources.h"
14 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/material_design/material_design_controller.h" 15 #include "ui/base/material_design/material_design_controller.h"
16 #include "ui/base/theme_provider.h" 16 #include "ui/base/theme_provider.h"
17 #include "ui/gfx/color_palette.h" 17 #include "ui/gfx/color_palette.h"
18 #include "ui/gfx/color_utils.h" 18 #include "ui/gfx/color_utils.h"
19 #include "ui/views/animation/button_ink_drop_delegate.h"
19 #include "ui/views/controls/image_view.h" 20 #include "ui/views/controls/image_view.h"
20 #include "ui/views/controls/label.h" 21 #include "ui/views/controls/label.h"
21 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
22 23
23 24
24 namespace { 25 namespace {
25 // Time spent with animation fully open. 26 // Time spent with animation fully open.
26 const int kStayOpenTimeMS = 3200; 27 const int kStayOpenTimeMS = 3200;
27 } 28 }
28 29
(...skipping 10 matching lines...) Expand all
39 SkColor parent_background_color) 40 SkColor parent_background_color)
40 : IconLabelBubbleView(0, 41 : IconLabelBubbleView(0,
41 font_list, 42 font_list,
42 parent_background_color, 43 parent_background_color,
43 false), 44 false),
44 parent_(parent), 45 parent_(parent),
45 content_setting_image_model_(image_model), 46 content_setting_image_model_(image_model),
46 slide_animator_(this), 47 slide_animator_(this),
47 pause_animation_(false), 48 pause_animation_(false),
48 pause_animation_state_(0.0), 49 pause_animation_state_(0.0),
49 bubble_widget_(NULL) { 50 bubble_widget_(nullptr),
msw 2016/01/29 01:10:10 you can probably remove the |bubble_widget_| membe
varkha 2016/01/29 02:23:19 Ouch. Done.
51 suppress_mouse_released_action_(false),
52 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)) {
50 if (!ui::MaterialDesignController::IsModeMaterial()) { 53 if (!ui::MaterialDesignController::IsModeMaterial()) {
51 static const int kBackgroundImages[] = 54 static const int kBackgroundImages[] =
52 IMAGE_GRID(IDR_OMNIBOX_CONTENT_SETTING_BUBBLE); 55 IMAGE_GRID(IDR_OMNIBOX_CONTENT_SETTING_BUBBLE);
53 SetBackgroundImageGrid(kBackgroundImages); 56 SetBackgroundImageGrid(kBackgroundImages);
54 } 57 }
55 58
59 // TODO(varkha): Provide standard ink drop dimensions in LayoutConstants.
56 image()->SetHorizontalAlignment(views::ImageView::LEADING); 60 image()->SetHorizontalAlignment(views::ImageView::LEADING);
57 image()->set_interactive(true); 61 image()->set_interactive(true);
62 image()->EnableCanvasFlippingForRTLUI(true);
63 image()->SetAccessibilityFocusable(true);
58 label()->SetElideBehavior(gfx::NO_ELIDE); 64 label()->SetElideBehavior(gfx::NO_ELIDE);
59 65
60 slide_animator_.SetSlideDuration(kAnimationDurationMS); 66 slide_animator_.SetSlideDuration(kAnimationDurationMS);
61 slide_animator_.SetTweenType(gfx::Tween::LINEAR); 67 slide_animator_.SetTweenType(gfx::Tween::LINEAR);
68
69 const int kInkDropLargeSize = 32;
70 const int kInkDropLargeCornerRadius = 5;
71 const int kInkDropSmallSize = 24;
72 const int kInkDropSmallCornerRadius = 2;
73 ink_drop_delegate_->SetInkDropSize(
74 kInkDropLargeSize, kInkDropLargeCornerRadius, kInkDropSmallSize,
75 kInkDropSmallCornerRadius);
62 } 76 }
63 77
64 ContentSettingImageView::~ContentSettingImageView() { 78 ContentSettingImageView::~ContentSettingImageView() {
65 if (bubble_widget_) 79 if (bubble_widget_)
66 bubble_widget_->RemoveObserver(this); 80 bubble_widget_->RemoveObserver(this);
67 } 81 }
68 82
69 void ContentSettingImageView::Update(content::WebContents* web_contents) { 83 void ContentSettingImageView::Update(content::WebContents* web_contents) {
70 // Note: We explicitly want to call this even if |web_contents| is NULL, so we 84 // Note: We explicitly want to call this even if |web_contents| is NULL, so we
71 // get hidden properly while the user is editing the omnibox. 85 // get hidden properly while the user is editing the omnibox.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 158
145 void ContentSettingImageView::AnimationCanceled( 159 void ContentSettingImageView::AnimationCanceled(
146 const gfx::Animation* animation) { 160 const gfx::Animation* animation) {
147 AnimationEnded(animation); 161 AnimationEnded(animation);
148 } 162 }
149 163
150 const char* ContentSettingImageView::GetClassName() const { 164 const char* ContentSettingImageView::GetClassName() const {
151 return "ContentSettingsImageView"; 165 return "ContentSettingsImageView";
152 } 166 }
153 167
168 void ContentSettingImageView::Layout() {
169 IconLabelBubbleView::Layout();
170 ink_drop_delegate_->OnLayout();
171 }
172
173 void ContentSettingImageView::OnBoundsChanged(
174 const gfx::Rect& previous_bounds) {
175 if (bubble_view_)
176 bubble_view_->OnAnchorBoundsChanged();
177 ink_drop_delegate_->OnLayout();
178 }
179
154 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { 180 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) {
181 // If the bubble is showing then don't reshow it when the mouse is released.
182 suppress_mouse_released_action_ = IsBubbleShowing();
183 if (!suppress_mouse_released_action_ && !label()->visible())
184 ink_drop_delegate_->OnAction(views::InkDropState::ACTION_PENDING);
185
155 // We want to show the bubble on mouse release; that is the standard behavior 186 // We want to show the bubble on mouse release; that is the standard behavior
156 // for buttons. 187 // for buttons.
157 return true; 188 return true;
158 } 189 }
159 190
160 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) { 191 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) {
161 if (HitTestPoint(event.location())) 192 // If this is the second click on this view then the bubble was showing on the
193 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by
194 // doing nothing here.
195 if (suppress_mouse_released_action_) {
196 suppress_mouse_released_action_ = false;
197 return;
198 }
199 const bool activated = HitTestPoint(event.location());
200 if (!label()->visible()) {
201 ink_drop_delegate_->OnAction(activated ? views::InkDropState::ACTIVATED
202 : views::InkDropState::HIDDEN);
203 }
204 if (activated)
162 OnClick(); 205 OnClick();
163 } 206 }
164 207
165 void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) { 208 void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) {
166 if (event->type() == ui::ET_GESTURE_TAP) 209 if (event->type() == ui::ET_GESTURE_TAP) {
210 if (!label()->visible())
211 ink_drop_delegate_->OnAction(views::InkDropState::ACTIVATED);
167 OnClick(); 212 OnClick();
213 }
168 if ((event->type() == ui::ET_GESTURE_TAP) || 214 if ((event->type() == ui::ET_GESTURE_TAP) ||
169 (event->type() == ui::ET_GESTURE_TAP_DOWN)) 215 (event->type() == ui::ET_GESTURE_TAP_DOWN))
170 event->SetHandled(); 216 event->SetHandled();
171 } 217 }
172 218
173 void ContentSettingImageView::OnNativeThemeChanged( 219 void ContentSettingImageView::OnNativeThemeChanged(
174 const ui::NativeTheme* native_theme) { 220 const ui::NativeTheme* native_theme) {
175 if (ui::MaterialDesignController::IsModeMaterial()) 221 if (ui::MaterialDesignController::IsModeMaterial())
176 UpdateImage(); 222 UpdateImage();
177 223
178 IconLabelBubbleView::OnNativeThemeChanged(native_theme); 224 IconLabelBubbleView::OnNativeThemeChanged(native_theme);
179 } 225 }
180 226
227 void ContentSettingImageView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
228 image()->SetPaintToLayer(true);
229 image()->SetFillsBoundsOpaquely(false);
230 SetPaintToLayer(true);
231 SetFillsBoundsOpaquely(false);
232 layer()->Add(ink_drop_layer);
233 layer()->StackAtBottom(ink_drop_layer);
234 }
235
236 void ContentSettingImageView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
237 layer()->Remove(ink_drop_layer);
238 SetFillsBoundsOpaquely(true);
239 SetPaintToLayer(false);
240 image()->SetFillsBoundsOpaquely(true);
241 image()->SetPaintToLayer(false);
242 }
243
244 gfx::Point ContentSettingImageView::CalculateInkDropCenter() const {
245 return GetLocalBounds().CenterPoint();
246 }
247
248 bool ContentSettingImageView::ShouldShowInkDropHover() const {
249 // location bar views don't show hover effect.
250 return false;
251 }
252
181 void ContentSettingImageView::OnWidgetDestroying(views::Widget* widget) { 253 void ContentSettingImageView::OnWidgetDestroying(views::Widget* widget) {
182 DCHECK_EQ(bubble_widget_, widget); 254 DCHECK_EQ(bubble_widget_, widget);
255 DCHECK(bubble_view_);
183 bubble_widget_->RemoveObserver(this); 256 bubble_widget_->RemoveObserver(this);
184 bubble_widget_ = NULL; 257 bubble_widget_ = nullptr;
258 bubble_view_ = nullptr;
185 259
186 if (pause_animation_) { 260 if (pause_animation_) {
187 slide_animator_.Reset(pause_animation_state_); 261 slide_animator_.Reset(pause_animation_state_);
188 pause_animation_ = false; 262 pause_animation_ = false;
189 slide_animator_.Show(); 263 slide_animator_.Show();
190 } 264 }
191 } 265 }
192 266
267 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget,
268 bool visible) {
269 // |widget| is a bubble that has just got shown / hidden.
270 if (!visible && !label()->visible())
271 ink_drop_delegate_->OnAction(views::InkDropState::DEACTIVATED);
272 }
273
193 void ContentSettingImageView::OnClick() { 274 void ContentSettingImageView::OnClick() {
194 if (slide_animator_.is_animating()) { 275 if (slide_animator_.is_animating()) {
195 if (!pause_animation_) { 276 if (!pause_animation_) {
196 pause_animation_ = true; 277 pause_animation_ = true;
197 pause_animation_state_ = slide_animator_.GetCurrentValue(); 278 pause_animation_state_ = slide_animator_.GetCurrentValue();
198 } 279 }
199 slide_animator_.Reset(); 280 slide_animator_.Reset();
200 } 281 }
201 282
202 content::WebContents* web_contents = parent_->GetWebContents(); 283 content::WebContents* web_contents = parent_->GetWebContents();
203 if (web_contents && !bubble_widget_) { 284 if (web_contents && !bubble_widget_) {
204 bubble_widget_ = 285 DCHECK(!bubble_view_);
205 parent_->delegate()->CreateViewsBubble(new ContentSettingBubbleContents( 286 bubble_view_ = new ContentSettingBubbleContents(
206 content_setting_image_model_->CreateBubbleModel( 287 content_setting_image_model_->CreateBubbleModel(
207 parent_->delegate()->GetContentSettingBubbleModelDelegate(), 288 parent_->delegate()->GetContentSettingBubbleModelDelegate(),
208 web_contents, parent_->profile()), 289 web_contents, parent_->profile()),
209 web_contents, this, views::BubbleBorder::TOP_RIGHT)); 290 web_contents, this, views::BubbleBorder::TOP_RIGHT);
291 bubble_widget_ = parent_->delegate()->CreateViewsBubble(bubble_view_);
210 bubble_widget_->AddObserver(this); 292 bubble_widget_->AddObserver(this);
211 bubble_widget_->Show(); 293 bubble_widget_->Show();
212 } 294 }
213 } 295 }
214 296
215 void ContentSettingImageView::UpdateImage() { 297 void ContentSettingImageView::UpdateImage() {
216 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); 298 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia());
217 image()->SetTooltipText(content_setting_image_model_->get_tooltip()); 299 image()->SetTooltipText(content_setting_image_model_->get_tooltip());
218 } 300 }
301
302 bool ContentSettingImageView::IsBubbleShowing() const {
303 return bubble_widget_ != nullptr;
304 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698