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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 text_label_->SetVisible(true); | 122 text_label_->SetVisible(true); |
123 slide_animator_.Show(); | 123 slide_animator_.Show(); |
124 } | 124 } |
125 | 125 |
126 content_settings->SetBlockageHasBeenIndicated( | 126 content_settings->SetBlockageHasBeenIndicated( |
127 content_setting_image_model_->get_content_settings_type()); | 127 content_setting_image_model_->get_content_settings_type()); |
128 } | 128 } |
129 | 129 |
130 // static | 130 // static |
131 int ContentSettingImageView::GetBubbleOuterPadding(bool by_icon) { | 131 int ContentSettingImageView::GetBubbleOuterPadding(bool by_icon) { |
132 return LocationBarView::GetItemPadding() - LocationBarView::kBubblePadding + | 132 return LocationBarView::kItemPadding - LocationBarView::kBubblePadding + |
133 (by_icon ? 0 : LocationBarView::kIconInternalPadding); | 133 (by_icon ? 0 : LocationBarView::kIconInternalPadding); |
134 } | 134 } |
135 | 135 |
136 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { | 136 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { |
137 slide_animator_.Reset(); | 137 slide_animator_.Reset(); |
138 if (!pause_animation_) { | 138 if (!pause_animation_) { |
139 text_label_->SetVisible(false); | 139 text_label_->SetVisible(false); |
140 parent_->Layout(); | 140 parent_->Layout(); |
141 parent_->SchedulePaint(); | 141 parent_->SchedulePaint(); |
142 } | 142 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 } | 177 } |
178 return size; | 178 return size; |
179 } | 179 } |
180 | 180 |
181 void ContentSettingImageView::Layout() { | 181 void ContentSettingImageView::Layout() { |
182 const int icon_width = icon_->GetPreferredSize().width(); | 182 const int icon_width = icon_->GetPreferredSize().width(); |
183 icon_->SetBounds( | 183 icon_->SetBounds( |
184 std::min((width() - icon_width) / 2, GetBubbleOuterPadding(true)), 0, | 184 std::min((width() - icon_width) / 2, GetBubbleOuterPadding(true)), 0, |
185 icon_width, height()); | 185 icon_width, height()); |
186 text_label_->SetBounds( | 186 text_label_->SetBounds( |
187 icon_->bounds().right() + LocationBarView::GetItemPadding(), 0, | 187 icon_->bounds().right() + LocationBarView::kItemPadding, 0, |
188 std::max(width() - GetTotalSpacingWhileAnimating() - icon_width, 0), | 188 std::max(width() - GetTotalSpacingWhileAnimating() - icon_width, 0), |
189 height()); | 189 height()); |
190 } | 190 } |
191 | 191 |
192 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { | 192 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { |
193 // We want to show the bubble on mouse release; that is the standard behavior | 193 // We want to show the bubble on mouse release; that is the standard behavior |
194 // for buttons. | 194 // for buttons. |
195 return true; | 195 return true; |
196 } | 196 } |
197 | 197 |
(...skipping 21 matching lines...) Expand all Loading... |
219 bubble_widget_ = NULL; | 219 bubble_widget_ = NULL; |
220 | 220 |
221 if (pause_animation_) { | 221 if (pause_animation_) { |
222 slide_animator_.Reset(pause_animation_state_); | 222 slide_animator_.Reset(pause_animation_state_); |
223 pause_animation_ = false; | 223 pause_animation_ = false; |
224 slide_animator_.Show(); | 224 slide_animator_.Show(); |
225 } | 225 } |
226 } | 226 } |
227 | 227 |
228 int ContentSettingImageView::GetTotalSpacingWhileAnimating() const { | 228 int ContentSettingImageView::GetTotalSpacingWhileAnimating() const { |
229 return GetBubbleOuterPadding(true) + LocationBarView::GetItemPadding() + | 229 return GetBubbleOuterPadding(true) + LocationBarView::kItemPadding + |
230 GetBubbleOuterPadding(false); | 230 GetBubbleOuterPadding(false); |
231 } | 231 } |
232 | 232 |
233 void ContentSettingImageView::OnClick() { | 233 void ContentSettingImageView::OnClick() { |
234 if (slide_animator_.is_animating()) { | 234 if (slide_animator_.is_animating()) { |
235 if (!pause_animation_) { | 235 if (!pause_animation_) { |
236 pause_animation_ = true; | 236 pause_animation_ = true; |
237 pause_animation_state_ = slide_animator_.GetCurrentValue(); | 237 pause_animation_state_ = slide_animator_.GetCurrentValue(); |
238 } | 238 } |
239 slide_animator_.Reset(); | 239 slide_animator_.Reset(); |
240 } | 240 } |
241 | 241 |
242 content::WebContents* web_contents = parent_->GetWebContents(); | 242 content::WebContents* web_contents = parent_->GetWebContents(); |
243 if (web_contents && !bubble_widget_) { | 243 if (web_contents && !bubble_widget_) { |
244 bubble_widget_ = | 244 bubble_widget_ = |
245 parent_->delegate()->CreateViewsBubble(new ContentSettingBubbleContents( | 245 parent_->delegate()->CreateViewsBubble(new ContentSettingBubbleContents( |
246 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 246 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
247 parent_->delegate()->GetContentSettingBubbleModelDelegate(), | 247 parent_->delegate()->GetContentSettingBubbleModelDelegate(), |
248 web_contents, parent_->profile(), | 248 web_contents, parent_->profile(), |
249 content_setting_image_model_->get_content_settings_type()), | 249 content_setting_image_model_->get_content_settings_type()), |
250 this, views::BubbleBorder::TOP_RIGHT)); | 250 this, views::BubbleBorder::TOP_RIGHT)); |
251 bubble_widget_->AddObserver(this); | 251 bubble_widget_->AddObserver(this); |
252 bubble_widget_->Show(); | 252 bubble_widget_->Show(); |
253 } | 253 } |
254 } | 254 } |
OLD | NEW |