OLD | NEW |
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/content_settings/tab_specific_content_settings.h" | 8 #include "chrome/browser/content_settings/tab_specific_content_settings.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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged | 71 // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged |
72 // even if |a| is a color with non-255 alpha. | 72 // even if |a| is a color with non-255 alpha. |
73 text_label_->SetBackgroundColor( | 73 text_label_->SetBackgroundColor( |
74 color_utils::AlphaBlend(SkColorSetA(background_image_color, 255), | 74 color_utils::AlphaBlend(SkColorSetA(background_image_color, 255), |
75 parent_background_color, | 75 parent_background_color, |
76 SkColorGetA(background_image_color))); | 76 SkColorGetA(background_image_color))); |
77 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 77 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
78 text_label_->SetElideBehavior(views::Label::NO_ELIDE); | 78 text_label_->SetElideBehavior(views::Label::NO_ELIDE); |
79 AddChildView(text_label_); | 79 AddChildView(text_label_); |
80 | 80 |
81 LocationBarView::InitTouchableLocationBarChildView(this); | |
82 | |
83 slide_animator_.SetSlideDuration(kAnimationDurationMS); | 81 slide_animator_.SetSlideDuration(kAnimationDurationMS); |
84 slide_animator_.SetTweenType(gfx::Tween::LINEAR); | 82 slide_animator_.SetTweenType(gfx::Tween::LINEAR); |
85 } | 83 } |
86 | 84 |
87 ContentSettingImageView::~ContentSettingImageView() { | 85 ContentSettingImageView::~ContentSettingImageView() { |
88 if (bubble_widget_) | 86 if (bubble_widget_) |
89 bubble_widget_->RemoveObserver(this); | 87 bubble_widget_->RemoveObserver(this); |
90 } | 88 } |
91 | 89 |
92 void ContentSettingImageView::Update(content::WebContents* web_contents) { | 90 void ContentSettingImageView::Update(content::WebContents* web_contents) { |
(...skipping 29 matching lines...) Expand all Loading... |
122 text_label_->SetVisible(true); | 120 text_label_->SetVisible(true); |
123 slide_animator_.Show(); | 121 slide_animator_.Show(); |
124 } | 122 } |
125 | 123 |
126 content_settings->SetBlockageHasBeenIndicated( | 124 content_settings->SetBlockageHasBeenIndicated( |
127 content_setting_image_model_->get_content_settings_type()); | 125 content_setting_image_model_->get_content_settings_type()); |
128 } | 126 } |
129 | 127 |
130 // static | 128 // static |
131 int ContentSettingImageView::GetBubbleOuterPadding(bool by_icon) { | 129 int ContentSettingImageView::GetBubbleOuterPadding(bool by_icon) { |
132 return LocationBarView::GetItemPadding() - LocationBarView::kBubblePadding + | 130 return LocationBarView::kItemPadding - LocationBarView::kBubblePadding + |
133 (by_icon ? 0 : LocationBarView::kIconInternalPadding); | 131 (by_icon ? 0 : LocationBarView::kIconInternalPadding); |
134 } | 132 } |
135 | 133 |
136 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { | 134 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { |
137 slide_animator_.Reset(); | 135 slide_animator_.Reset(); |
138 if (!pause_animation_) { | 136 if (!pause_animation_) { |
139 text_label_->SetVisible(false); | 137 text_label_->SetVisible(false); |
140 parent_->Layout(); | 138 parent_->Layout(); |
141 parent_->SchedulePaint(); | 139 parent_->SchedulePaint(); |
142 } | 140 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 } | 175 } |
178 return size; | 176 return size; |
179 } | 177 } |
180 | 178 |
181 void ContentSettingImageView::Layout() { | 179 void ContentSettingImageView::Layout() { |
182 const int icon_width = icon_->GetPreferredSize().width(); | 180 const int icon_width = icon_->GetPreferredSize().width(); |
183 icon_->SetBounds( | 181 icon_->SetBounds( |
184 std::min((width() - icon_width) / 2, GetBubbleOuterPadding(true)), 0, | 182 std::min((width() - icon_width) / 2, GetBubbleOuterPadding(true)), 0, |
185 icon_width, height()); | 183 icon_width, height()); |
186 text_label_->SetBounds( | 184 text_label_->SetBounds( |
187 icon_->bounds().right() + LocationBarView::GetItemPadding(), 0, | 185 icon_->bounds().right() + LocationBarView::kItemPadding, 0, |
188 std::max(width() - GetTotalSpacingWhileAnimating() - icon_width, 0), | 186 std::max(width() - GetTotalSpacingWhileAnimating() - icon_width, 0), |
189 height()); | 187 height()); |
190 } | 188 } |
191 | 189 |
192 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { | 190 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { |
193 // We want to show the bubble on mouse release; that is the standard behavior | 191 // We want to show the bubble on mouse release; that is the standard behavior |
194 // for buttons. | 192 // for buttons. |
195 return true; | 193 return true; |
196 } | 194 } |
197 | 195 |
(...skipping 21 matching lines...) Expand all Loading... |
219 bubble_widget_ = NULL; | 217 bubble_widget_ = NULL; |
220 | 218 |
221 if (pause_animation_) { | 219 if (pause_animation_) { |
222 slide_animator_.Reset(pause_animation_state_); | 220 slide_animator_.Reset(pause_animation_state_); |
223 pause_animation_ = false; | 221 pause_animation_ = false; |
224 slide_animator_.Show(); | 222 slide_animator_.Show(); |
225 } | 223 } |
226 } | 224 } |
227 | 225 |
228 int ContentSettingImageView::GetTotalSpacingWhileAnimating() const { | 226 int ContentSettingImageView::GetTotalSpacingWhileAnimating() const { |
229 return GetBubbleOuterPadding(true) + LocationBarView::GetItemPadding() + | 227 return GetBubbleOuterPadding(true) + LocationBarView::kItemPadding + |
230 GetBubbleOuterPadding(false); | 228 GetBubbleOuterPadding(false); |
231 } | 229 } |
232 | 230 |
233 void ContentSettingImageView::OnClick() { | 231 void ContentSettingImageView::OnClick() { |
234 if (slide_animator_.is_animating()) { | 232 if (slide_animator_.is_animating()) { |
235 if (!pause_animation_) { | 233 if (!pause_animation_) { |
236 pause_animation_ = true; | 234 pause_animation_ = true; |
237 pause_animation_state_ = slide_animator_.GetCurrentValue(); | 235 pause_animation_state_ = slide_animator_.GetCurrentValue(); |
238 } | 236 } |
239 slide_animator_.Reset(); | 237 slide_animator_.Reset(); |
240 } | 238 } |
241 | 239 |
242 content::WebContents* web_contents = parent_->GetWebContents(); | 240 content::WebContents* web_contents = parent_->GetWebContents(); |
243 if (web_contents && !bubble_widget_) { | 241 if (web_contents && !bubble_widget_) { |
244 bubble_widget_ = | 242 bubble_widget_ = |
245 parent_->delegate()->CreateViewsBubble(new ContentSettingBubbleContents( | 243 parent_->delegate()->CreateViewsBubble(new ContentSettingBubbleContents( |
246 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 244 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
247 parent_->delegate()->GetContentSettingBubbleModelDelegate(), | 245 parent_->delegate()->GetContentSettingBubbleModelDelegate(), |
248 web_contents, parent_->profile(), | 246 web_contents, parent_->profile(), |
249 content_setting_image_model_->get_content_settings_type()), | 247 content_setting_image_model_->get_content_settings_type()), |
250 this, views::BubbleBorder::TOP_RIGHT)); | 248 this, views::BubbleBorder::TOP_RIGHT)); |
251 bubble_widget_->AddObserver(this); | 249 bubble_widget_->AddObserver(this); |
252 bubble_widget_->Show(); | 250 bubble_widget_->Show(); |
253 } | 251 } |
254 } | 252 } |
OLD | NEW |