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

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 (missing member init) 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_view_(nullptr),
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_view_ && bubble_view_->GetWidget())
66 bubble_widget_->RemoveObserver(this); 80 bubble_view_->GetWidget()->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.
72 content_setting_image_model_->UpdateFromWebContents(web_contents); 86 content_setting_image_model_->UpdateFromWebContents(web_contents);
73 87
74 if (!content_setting_image_model_->is_visible()) { 88 if (!content_setting_image_model_->is_visible()) {
75 SetVisible(false); 89 SetVisible(false);
76 return; 90 return;
(...skipping 67 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(bubble_view_);
183 bubble_widget_->RemoveObserver(this); 255 DCHECK_EQ(bubble_view_->GetWidget(), widget);
184 bubble_widget_ = NULL; 256 widget->RemoveObserver(this);
257 bubble_view_ = nullptr;
185 258
186 if (pause_animation_) { 259 if (pause_animation_) {
187 slide_animator_.Reset(pause_animation_state_); 260 slide_animator_.Reset(pause_animation_state_);
188 pause_animation_ = false; 261 pause_animation_ = false;
189 slide_animator_.Show(); 262 slide_animator_.Show();
190 } 263 }
191 } 264 }
192 265
266 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget,
267 bool visible) {
268 // |widget| is a bubble that has just got shown / hidden.
269 if (!visible && !label()->visible())
270 ink_drop_delegate_->OnAction(views::InkDropState::DEACTIVATED);
271 }
272
193 void ContentSettingImageView::OnClick() { 273 void ContentSettingImageView::OnClick() {
194 if (slide_animator_.is_animating()) { 274 if (slide_animator_.is_animating()) {
195 if (!pause_animation_) { 275 if (!pause_animation_) {
196 pause_animation_ = true; 276 pause_animation_ = true;
197 pause_animation_state_ = slide_animator_.GetCurrentValue(); 277 pause_animation_state_ = slide_animator_.GetCurrentValue();
198 } 278 }
199 slide_animator_.Reset(); 279 slide_animator_.Reset();
200 } 280 }
201 281
202 content::WebContents* web_contents = parent_->GetWebContents(); 282 content::WebContents* web_contents = parent_->GetWebContents();
203 if (web_contents && !bubble_widget_) { 283 if (web_contents && !bubble_view_) {
204 bubble_widget_ = 284 bubble_view_ = new ContentSettingBubbleContents(
205 parent_->delegate()->CreateViewsBubble(new ContentSettingBubbleContents( 285 content_setting_image_model_->CreateBubbleModel(
206 content_setting_image_model_->CreateBubbleModel( 286 parent_->delegate()->GetContentSettingBubbleModelDelegate(),
207 parent_->delegate()->GetContentSettingBubbleModelDelegate(), 287 web_contents, parent_->profile()),
208 web_contents, parent_->profile()), 288 web_contents, this, views::BubbleBorder::TOP_RIGHT);
209 web_contents, this, views::BubbleBorder::TOP_RIGHT)); 289 views::Widget* bubble_widget =
210 bubble_widget_->AddObserver(this); 290 parent_->delegate()->CreateViewsBubble(bubble_view_);
211 bubble_widget_->Show(); 291 bubble_widget->AddObserver(this);
292 bubble_widget->Show();
212 } 293 }
213 } 294 }
214 295
215 void ContentSettingImageView::UpdateImage() { 296 void ContentSettingImageView::UpdateImage() {
216 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); 297 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia());
217 image()->SetTooltipText(content_setting_image_model_->get_tooltip()); 298 image()->SetTooltipText(content_setting_image_model_->get_tooltip());
218 } 299 }
300
301 bool ContentSettingImageView::IsBubbleShowing() const {
302 return bubble_view_ != nullptr;
303 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698