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

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

Issue 1834933002: Misc. cleanup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix missing spacing Created 4 years, 8 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"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 if (string_id && !label()->visible()) { 99 if (string_id && !label()->visible()) {
100 ink_drop_delegate_->OnAction(views::InkDropState::HIDDEN); 100 ink_drop_delegate_->OnAction(views::InkDropState::HIDDEN);
101 SetLabel(l10n_util::GetStringUTF16(string_id)); 101 SetLabel(l10n_util::GetStringUTF16(string_id));
102 label()->SetVisible(true); 102 label()->SetVisible(true);
103 slide_animator_.Show(); 103 slide_animator_.Show();
104 } 104 }
105 105
106 content_setting_image_model_->SetAnimationHasRun(web_contents); 106 content_setting_image_model_->SetAnimationHasRun(web_contents);
107 } 107 }
108 108
109 SkColor ContentSettingImageView::GetTextColor() const {
110 return GetNativeTheme()->GetSystemColor(
111 ui::NativeTheme::kColorId_TextfieldDefaultColor);
112 }
113
114 SkColor ContentSettingImageView::GetBorderColor() const {
115 return gfx::kGoogleYellow700;
116 }
117
118 bool ContentSettingImageView::ShouldShowBackground() const {
119 return (!IsShrinking() || label()->width() > 0) &&
120 (slide_animator_.is_animating() || pause_animation_);
121 }
122
123 double ContentSettingImageView::WidthMultiplier() const {
124 double state = pause_animation_ ? pause_animation_state_
125 : slide_animator_.GetCurrentValue();
126 // The fraction of the animation we'll spend animating the string into view,
127 // which is also the fraction we'll spend animating it closed; total
128 // animation (slide out, show, then slide in) is 1.0.
129 const double kOpenFraction =
130 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS;
131 double size_fraction = 1.0;
132 if (state < kOpenFraction)
133 size_fraction = state / kOpenFraction;
134 if (state > (1.0 - kOpenFraction))
135 size_fraction = (1.0 - state) / kOpenFraction;
136 return size_fraction;
137 }
138
139 bool ContentSettingImageView::IsShrinking() const {
140 const double kOpenFraction =
141 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS;
142 return (!pause_animation_ && slide_animator_.is_animating() &&
143 slide_animator_.GetCurrentValue() > (1.0 - kOpenFraction));
144 }
145
146 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) {
147 slide_animator_.Reset();
148 if (!pause_animation_) {
149 label()->SetVisible(false);
150 parent_->Layout();
151 parent_->SchedulePaint();
152 }
153 }
154
155 void ContentSettingImageView::AnimationProgressed(
156 const gfx::Animation* animation) {
157 if (!pause_animation_) {
158 parent_->Layout();
159 parent_->SchedulePaint();
160 }
161 }
162
163 void ContentSettingImageView::AnimationCanceled(
164 const gfx::Animation* animation) {
165 AnimationEnded(animation);
166 }
167
168 const char* ContentSettingImageView::GetClassName() const { 109 const char* ContentSettingImageView::GetClassName() const {
169 return "ContentSettingsImageView"; 110 return "ContentSettingsImageView";
170 } 111 }
171 112
172 void ContentSettingImageView::OnBoundsChanged( 113 void ContentSettingImageView::OnBoundsChanged(
173 const gfx::Rect& previous_bounds) { 114 const gfx::Rect& previous_bounds) {
174 if (bubble_view_) 115 if (bubble_view_)
175 bubble_view_->OnAnchorBoundsChanged(); 116 bubble_view_->OnAnchorBoundsChanged();
176 } 117 }
177 118
178 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { 119 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) {
179 // If the bubble is showing then don't reshow it when the mouse is released. 120 // If the bubble is showing then don't reshow it when the mouse is released.
180 suppress_mouse_released_action_ = IsBubbleShowing(); 121 suppress_mouse_released_action_ = bubble_view_ != nullptr;
181 if (!suppress_mouse_released_action_ && !label()->visible()) 122 if (!suppress_mouse_released_action_ && !label()->visible())
182 ink_drop_delegate_->OnAction(views::InkDropState::ACTION_PENDING); 123 ink_drop_delegate_->OnAction(views::InkDropState::ACTION_PENDING);
183 124
184 // We want to show the bubble on mouse release; that is the standard behavior 125 // We want to show the bubble on mouse release; that is the standard behavior
185 // for buttons. 126 // for buttons.
186 return true; 127 return true;
187 } 128 }
188 129
189 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) { 130 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) {
190 // If this is the second click on this view then the bubble was showing on the 131 // If this is the second click on this view then the bubble was showing on the
(...skipping 27 matching lines...) Expand all
218 } 159 }
219 160
220 void ContentSettingImageView::OnNativeThemeChanged( 161 void ContentSettingImageView::OnNativeThemeChanged(
221 const ui::NativeTheme* native_theme) { 162 const ui::NativeTheme* native_theme) {
222 if (ui::MaterialDesignController::IsModeMaterial()) 163 if (ui::MaterialDesignController::IsModeMaterial())
223 UpdateImage(); 164 UpdateImage();
224 165
225 IconLabelBubbleView::OnNativeThemeChanged(native_theme); 166 IconLabelBubbleView::OnNativeThemeChanged(native_theme);
226 } 167 }
227 168
169 SkColor ContentSettingImageView::GetTextColor() const {
170 return GetNativeTheme()->GetSystemColor(
171 ui::NativeTheme::kColorId_TextfieldDefaultColor);
172 }
173
174 SkColor ContentSettingImageView::GetBorderColor() const {
175 return gfx::kGoogleYellow700;
176 }
177
178 bool ContentSettingImageView::ShouldShowBackground() const {
179 return (!IsShrinking() || label()->width() > 0) &&
180 (slide_animator_.is_animating() || pause_animation_);
181 }
182
183 double ContentSettingImageView::WidthMultiplier() const {
184 double state = pause_animation_ ? pause_animation_state_
185 : slide_animator_.GetCurrentValue();
186 // The fraction of the animation we'll spend animating the string into view,
187 // which is also the fraction we'll spend animating it closed; total
188 // animation (slide out, show, then slide in) is 1.0.
189 const double kOpenFraction =
190 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS;
191 double size_fraction = 1.0;
192 if (state < kOpenFraction)
193 size_fraction = state / kOpenFraction;
194 if (state > (1.0 - kOpenFraction))
195 size_fraction = (1.0 - state) / kOpenFraction;
196 return size_fraction;
197 }
198
199 bool ContentSettingImageView::IsShrinking() const {
200 const double kOpenFraction =
201 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS;
202 return (!pause_animation_ && slide_animator_.is_animating() &&
203 slide_animator_.GetCurrentValue() > (1.0 - kOpenFraction));
204 }
205
206 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) {
207 slide_animator_.Reset();
208 if (!pause_animation_) {
209 label()->SetVisible(false);
210 parent_->Layout();
211 parent_->SchedulePaint();
212 }
213 }
214
215 void ContentSettingImageView::AnimationProgressed(
216 const gfx::Animation* animation) {
217 if (!pause_animation_) {
218 parent_->Layout();
219 parent_->SchedulePaint();
220 }
221 }
222
223 void ContentSettingImageView::AnimationCanceled(
224 const gfx::Animation* animation) {
225 AnimationEnded(animation);
226 }
227
228 void ContentSettingImageView::OnWidgetDestroying(views::Widget* widget) { 228 void ContentSettingImageView::OnWidgetDestroying(views::Widget* widget) {
229 DCHECK(bubble_view_); 229 DCHECK(bubble_view_);
230 DCHECK_EQ(bubble_view_->GetWidget(), widget); 230 DCHECK_EQ(bubble_view_->GetWidget(), widget);
231 widget->RemoveObserver(this); 231 widget->RemoveObserver(this);
232 bubble_view_ = nullptr; 232 bubble_view_ = nullptr;
233 233
234 if (pause_animation_) { 234 if (pause_animation_) {
235 slide_animator_.Reset(pause_animation_state_); 235 slide_animator_.Reset(pause_animation_state_);
236 pause_animation_ = false; 236 pause_animation_ = false;
237 slide_animator_.Show(); 237 slide_animator_.Show();
(...skipping 11 matching lines...) Expand all
249 if (slide_animator_.is_animating()) { 249 if (slide_animator_.is_animating()) {
250 // If the user clicks while we're animating, the bubble arrow will be 250 // If the user clicks while we're animating, the bubble arrow will be
251 // pointing to the image, and if we allow the animation to keep running, the 251 // pointing to the image, and if we allow the animation to keep running, the
252 // image will move away from the arrow (or we'll have to move the bubble, 252 // image will move away from the arrow (or we'll have to move the bubble,
253 // which is even worse). So we want to stop the animation. We have two 253 // which is even worse). So we want to stop the animation. We have two
254 // choices: jump to the final post-animation state (no label visible), or 254 // choices: jump to the final post-animation state (no label visible), or
255 // pause the animation where we are and continue running after the bubble 255 // pause the animation where we are and continue running after the bubble
256 // closes. The former looks more jerky, so we avoid it unless the animation 256 // closes. The former looks more jerky, so we avoid it unless the animation
257 // hasn't even fully exposed the image yet, in which case pausing with half 257 // hasn't even fully exposed the image yet, in which case pausing with half
258 // an image visible will look broken. 258 // an image visible will look broken.
259 const int final_width = image()->GetPreferredSize().width() + 259 if (!pause_animation_ && ShouldShowBackground() &&
260 GetBubbleOuterPadding(true) + 260 (width() > MinimumWidthForImageWithBackgroundShown())) {
261 GetBubbleOuterPadding(false);
262 if (!pause_animation_ && ShouldShowBackground() && width() > final_width) {
263 pause_animation_ = true; 261 pause_animation_ = true;
264 pause_animation_state_ = slide_animator_.GetCurrentValue(); 262 pause_animation_state_ = slide_animator_.GetCurrentValue();
265 } 263 }
266 slide_animator_.Reset(); 264 slide_animator_.Reset();
267 } 265 }
268 266
269 content::WebContents* web_contents = parent_->GetWebContents(); 267 content::WebContents* web_contents = parent_->GetWebContents();
270 if (web_contents && !bubble_view_) { 268 if (web_contents && !bubble_view_) {
271 bubble_view_ = new ContentSettingBubbleContents( 269 bubble_view_ = new ContentSettingBubbleContents(
272 content_setting_image_model_->CreateBubbleModel( 270 content_setting_image_model_->CreateBubbleModel(
(...skipping 13 matching lines...) Expand all
286 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); 284 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT);
287 } 285 }
288 bubble_widget->Show(); 286 bubble_widget->Show();
289 } 287 }
290 } 288 }
291 289
292 void ContentSettingImageView::UpdateImage() { 290 void ContentSettingImageView::UpdateImage() {
293 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); 291 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia());
294 image()->SetTooltipText(content_setting_image_model_->get_tooltip()); 292 image()->SetTooltipText(content_setting_image_model_->get_tooltip());
295 } 293 }
296
297 bool ContentSettingImageView::IsBubbleShowing() const {
298 return bubble_view_ != nullptr;
299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698