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

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

Issue 2041033002: Moved ButtonInkDropDelegate logic into InkDropHostView and deleted InkDropDelegates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed merge conflict in custom_button.cc Created 4 years, 6 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"
20 #include "ui/views/controls/image_view.h" 19 #include "ui/views/controls/image_view.h"
21 #include "ui/views/controls/label.h" 20 #include "ui/views/controls/label.h"
22 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
23 22
24 namespace { 23 namespace {
25 // Time spent with animation fully open. 24 // Time spent with animation fully open.
26 const int kStayOpenTimeMS = 3200; 25 const int kStayOpenTimeMS = 3200;
27 } 26 }
28 27
29 28
30 // static 29 // static
31 const int ContentSettingImageView::kOpenTimeMS = 150; 30 const int ContentSettingImageView::kOpenTimeMS = 150;
32 const int ContentSettingImageView::kAnimationDurationMS = 31 const int ContentSettingImageView::kAnimationDurationMS =
33 (kOpenTimeMS * 2) + kStayOpenTimeMS; 32 (kOpenTimeMS * 2) + kStayOpenTimeMS;
34 33
35 ContentSettingImageView::ContentSettingImageView( 34 ContentSettingImageView::ContentSettingImageView(
36 ContentSettingImageModel* image_model, 35 ContentSettingImageModel* image_model,
37 LocationBarView* parent, 36 LocationBarView* parent,
38 const gfx::FontList& font_list, 37 const gfx::FontList& font_list,
39 SkColor parent_background_color) 38 SkColor parent_background_color)
40 : IconLabelBubbleView(0, font_list, parent_background_color, false), 39 : IconLabelBubbleView(0, font_list, parent_background_color, false),
41 parent_(parent), 40 parent_(parent),
42 content_setting_image_model_(image_model), 41 content_setting_image_model_(image_model),
43 slide_animator_(this), 42 slide_animator_(this),
44 pause_animation_(false), 43 pause_animation_(false),
45 pause_animation_state_(0.0), 44 pause_animation_state_(0.0),
46 bubble_view_(nullptr), 45 bubble_view_(nullptr),
47 suppress_mouse_released_action_(false) { 46 suppress_mouse_released_action_(false) {
48 set_ink_drop_delegate( 47 SetHasInkDrop(true);
49 base::WrapUnique(new views::ButtonInkDropDelegate(this, this)));
50 if (!ui::MaterialDesignController::IsModeMaterial()) { 48 if (!ui::MaterialDesignController::IsModeMaterial()) {
51 static const int kBackgroundImages[] = 49 static const int kBackgroundImages[] =
52 IMAGE_GRID(IDR_OMNIBOX_CONTENT_SETTING_BUBBLE); 50 IMAGE_GRID(IDR_OMNIBOX_CONTENT_SETTING_BUBBLE);
53 SetBackgroundImageGrid(kBackgroundImages); 51 SetBackgroundImageGrid(kBackgroundImages);
54 } 52 }
55 53
56 image()->SetHorizontalAlignment(base::i18n::IsRTL() 54 image()->SetHorizontalAlignment(base::i18n::IsRTL()
57 ? views::ImageView::TRAILING 55 ? views::ImageView::TRAILING
58 : views::ImageView::LEADING); 56 : views::ImageView::LEADING);
59 image()->set_interactive(true); 57 image()->set_interactive(true);
(...skipping 27 matching lines...) Expand all
87 // If the content usage or blockage should be indicated to the user, start the 85 // If the content usage or blockage should be indicated to the user, start the
88 // animation and record that the icon has been shown. 86 // animation and record that the icon has been shown.
89 if (!content_setting_image_model_->ShouldRunAnimation(web_contents)) 87 if (!content_setting_image_model_->ShouldRunAnimation(web_contents))
90 return; 88 return;
91 89
92 // We just ignore this blockage if we're already showing some other string to 90 // We just ignore this blockage if we're already showing some other string to
93 // the user. If this becomes a problem, we could design some sort of queueing 91 // the user. If this becomes a problem, we could design some sort of queueing
94 // mechanism to show one after the other, but it doesn't seem important now. 92 // mechanism to show one after the other, but it doesn't seem important now.
95 int string_id = content_setting_image_model_->explanatory_string_id(); 93 int string_id = content_setting_image_model_->explanatory_string_id();
96 if (string_id && !label()->visible()) { 94 if (string_id && !label()->visible()) {
97 ink_drop_delegate()->OnAction(views::InkDropState::HIDDEN); 95 AnimateInkDrop(views::InkDropState::HIDDEN);
98 SetLabel(l10n_util::GetStringUTF16(string_id)); 96 SetLabel(l10n_util::GetStringUTF16(string_id));
99 label()->SetVisible(true); 97 label()->SetVisible(true);
100 slide_animator_.Show(); 98 slide_animator_.Show();
101 } 99 }
102 100
103 content_setting_image_model_->SetAnimationHasRun(web_contents); 101 content_setting_image_model_->SetAnimationHasRun(web_contents);
104 } 102 }
105 103
106 const char* ContentSettingImageView::GetClassName() const { 104 const char* ContentSettingImageView::GetClassName() const {
107 return "ContentSettingsImageView"; 105 return "ContentSettingsImageView";
108 } 106 }
109 107
110 void ContentSettingImageView::OnBoundsChanged( 108 void ContentSettingImageView::OnBoundsChanged(
111 const gfx::Rect& previous_bounds) { 109 const gfx::Rect& previous_bounds) {
112 if (bubble_view_) 110 if (bubble_view_)
113 bubble_view_->OnAnchorBoundsChanged(); 111 bubble_view_->OnAnchorBoundsChanged();
114 } 112 }
115 113
116 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { 114 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) {
117 // If the bubble is showing then don't reshow it when the mouse is released. 115 // If the bubble is showing then don't reshow it when the mouse is released.
118 suppress_mouse_released_action_ = bubble_view_ != nullptr; 116 suppress_mouse_released_action_ = bubble_view_ != nullptr;
119 if (!suppress_mouse_released_action_ && !label()->visible()) 117 if (!suppress_mouse_released_action_ && !label()->visible())
120 ink_drop_delegate()->OnAction(views::InkDropState::ACTION_PENDING); 118 AnimateInkDrop(views::InkDropState::ACTION_PENDING);
121 119
122 // We want to show the bubble on mouse release; that is the standard behavior 120 // We want to show the bubble on mouse release; that is the standard behavior
123 // for buttons. 121 // for buttons.
124 return true; 122 return true;
125 } 123 }
126 124
127 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) { 125 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) {
128 // If this is the second click on this view then the bubble was showing on the 126 // If this is the second click on this view then the bubble was showing on the
129 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by 127 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by
130 // doing nothing here. 128 // doing nothing here.
131 if (suppress_mouse_released_action_) { 129 if (suppress_mouse_released_action_) {
132 suppress_mouse_released_action_ = false; 130 suppress_mouse_released_action_ = false;
133 return; 131 return;
134 } 132 }
135 const bool activated = HitTestPoint(event.location()); 133 const bool activated = HitTestPoint(event.location());
136 if (!label()->visible() && !activated) 134 if (!label()->visible() && !activated)
137 ink_drop_delegate()->OnAction(views::InkDropState::HIDDEN); 135 AnimateInkDrop(views::InkDropState::HIDDEN);
138 if (activated) 136 if (activated)
139 OnActivate(); 137 OnActivate();
140 } 138 }
141 139
142 void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) { 140 void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) {
143 if (event->type() == ui::ET_GESTURE_TAP) 141 if (event->type() == ui::ET_GESTURE_TAP)
144 OnActivate(); 142 OnActivate();
145 if ((event->type() == ui::ET_GESTURE_TAP) || 143 if ((event->type() == ui::ET_GESTURE_TAP) ||
146 (event->type() == ui::ET_GESTURE_TAP_DOWN)) 144 (event->type() == ui::ET_GESTURE_TAP_DOWN))
147 event->SetHandled(); 145 event->SetHandled();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 web_contents, this, views::BubbleBorder::TOP_RIGHT); 219 web_contents, this, views::BubbleBorder::TOP_RIGHT);
222 views::Widget* bubble_widget = 220 views::Widget* bubble_widget =
223 views::BubbleDialogDelegateView::CreateBubble(bubble_view_); 221 views::BubbleDialogDelegateView::CreateBubble(bubble_view_);
224 bubble_widget->AddObserver(this); 222 bubble_widget->AddObserver(this);
225 // This is triggered by an input event. If the user clicks the icon while 223 // This is triggered by an input event. If the user clicks the icon while
226 // it's not animating, the icon will be placed in an active state, so the 224 // it's not animating, the icon will be placed in an active state, so the
227 // bubble doesn't need an arrow. If the user clicks during an animation, 225 // bubble doesn't need an arrow. If the user clicks during an animation,
228 // the animation simply pauses and no other visible state change occurs, so 226 // the animation simply pauses and no other visible state change occurs, so
229 // show the arrow in this case. 227 // show the arrow in this case.
230 if (ui::MaterialDesignController::IsModeMaterial() && !pause_animation_) { 228 if (ui::MaterialDesignController::IsModeMaterial() && !pause_animation_) {
231 ink_drop_delegate()->OnAction(views::InkDropState::ACTIVATED); 229 AnimateInkDrop(views::InkDropState::ACTIVATED);
232 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); 230 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT);
233 } 231 }
234 bubble_widget->Show(); 232 bubble_widget->Show();
235 } 233 }
236 234
237 return true; 235 return true;
238 } 236 }
239 237
240 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { 238 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) {
241 slide_animator_.Reset(); 239 slide_animator_.Reset();
(...skipping 27 matching lines...) Expand all
269 slide_animator_.Reset(pause_animation_state_); 267 slide_animator_.Reset(pause_animation_state_);
270 pause_animation_ = false; 268 pause_animation_ = false;
271 slide_animator_.Show(); 269 slide_animator_.Show();
272 } 270 }
273 } 271 }
274 272
275 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, 273 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget,
276 bool visible) { 274 bool visible) {
277 // |widget| is a bubble that has just got shown / hidden. 275 // |widget| is a bubble that has just got shown / hidden.
278 if (!visible && !label()->visible()) 276 if (!visible && !label()->visible())
279 ink_drop_delegate()->OnAction(views::InkDropState::DEACTIVATED); 277 AnimateInkDrop(views::InkDropState::DEACTIVATED);
280 } 278 }
281 279
282 void ContentSettingImageView::UpdateImage() { 280 void ContentSettingImageView::UpdateImage() {
283 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); 281 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia());
284 image()->SetTooltipText(content_setting_image_model_->get_tooltip()); 282 image()->SetTooltipText(content_setting_image_model_->get_tooltip());
285 } 283 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/bubble_icon_view.cc ('k') | chrome/browser/ui/views/toolbar/app_menu_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698