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

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

Issue 16115010: ContentSettingImageView cleanup, phase 3. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/location_bar/content_setting_image_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/utf_string_conversions.h" 7 #include "base/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 27 matching lines...) Expand all
38 LocationBarView* parent, 38 LocationBarView* parent,
39 const gfx::Font& font, 39 const gfx::Font& font,
40 int font_y_offset, 40 int font_y_offset,
41 SkColor font_color) 41 SkColor font_color)
42 : parent_(parent), 42 : parent_(parent),
43 content_setting_image_model_( 43 content_setting_image_model_(
44 ContentSettingImageModel::CreateContentSettingImageModel( 44 ContentSettingImageModel::CreateContentSettingImageModel(
45 content_type)), 45 content_type)),
46 background_painter_(new views::HorizontalPainter(background_images)), 46 background_painter_(new views::HorizontalPainter(background_images)),
47 icon_(new views::ImageView), 47 icon_(new views::ImageView),
48 text_label_(NULL), 48 text_label_(new views::Label),
49 slide_animator_(this), 49 slide_animator_(this),
50 pause_animation_(false), 50 pause_animation_(false),
51 pause_animation_state_(0.0), 51 pause_animation_state_(0.0),
52 bubble_widget_(NULL), 52 bubble_widget_(NULL) {
53 font_(font),
54 text_size_(0) {
55 SetLayoutManager(new views::BoxLayout(
56 views::BoxLayout::kHorizontal, 0, 0, 0));
57 icon_->SetHorizontalAlignment(views::ImageView::LEADING); 53 icon_->SetHorizontalAlignment(views::ImageView::LEADING);
58 AddChildView(icon_); 54 AddChildView(icon_);
55
56 text_label_->SetVisible(false);
57 text_label_->set_border(
58 views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0));
59 text_label_->SetFont(font);
60 text_label_->SetEnabledColor(font_color);
61 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
62 text_label_->SetElideBehavior(views::Label::NO_ELIDE);
63 AddChildView(text_label_);
64
59 TouchableLocationBarView::Init(this); 65 TouchableLocationBarView::Init(this);
60 66
61 slide_animator_.SetSlideDuration(kAnimationDurationMS); 67 slide_animator_.SetSlideDuration(kAnimationDurationMS);
62 slide_animator_.SetTweenType(ui::Tween::LINEAR); 68 slide_animator_.SetTweenType(ui::Tween::LINEAR);
63 } 69 }
64 70
65 ContentSettingImageView::~ContentSettingImageView() { 71 ContentSettingImageView::~ContentSettingImageView() {
66 if (bubble_widget_) 72 if (bubble_widget_)
67 bubble_widget_->RemoveObserver(this); 73 bubble_widget_->RemoveObserver(this);
68 } 74 }
(...skipping 23 matching lines...) Expand all
92 TabSpecificContentSettings::FromWebContents(web_contents) : NULL; 98 TabSpecificContentSettings::FromWebContents(web_contents) : NULL;
93 if (!content_settings || content_settings->IsBlockageIndicated( 99 if (!content_settings || content_settings->IsBlockageIndicated(
94 content_setting_image_model_->get_content_settings_type())) 100 content_setting_image_model_->get_content_settings_type()))
95 return; 101 return;
96 102
97 // We just ignore this blockage if we're already showing some other string to 103 // We just ignore this blockage if we're already showing some other string to
98 // the user. If this becomes a problem, we could design some sort of queueing 104 // the user. If this becomes a problem, we could design some sort of queueing
99 // mechanism to show one after the other, but it doesn't seem important now. 105 // mechanism to show one after the other, but it doesn't seem important now.
100 int string_id = content_setting_image_model_->explanatory_string_id(); 106 int string_id = content_setting_image_model_->explanatory_string_id();
101 if (string_id && !background_showing()) { 107 if (string_id && !background_showing()) {
102 // Initialize animated string. It will be cleared when animation is
103 // completed.
104 if (!text_label_) {
105 text_label_ = new views::Label;
106 text_label_->SetElideBehavior(views::Label::NO_ELIDE);
107 text_label_->SetFont(font_);
108 SetLayoutManager(new views::BoxLayout(
109 views::BoxLayout::kHorizontal, kHorizMargin, 0, kIconLabelSpacing));
110 AddChildView(text_label_);
111 }
112 text_label_->SetText(l10n_util::GetStringUTF16(string_id)); 108 text_label_->SetText(l10n_util::GetStringUTF16(string_id));
113 text_size_ = font_.GetStringWidth(text_label_->text()); 109 text_label_->SetVisible(true);
114 text_size_ += kHorizMargin;
115 slide_animator_.Show(); 110 slide_animator_.Show();
116 } 111 }
117 112
118 content_settings->SetBlockageHasBeenIndicated( 113 content_settings->SetBlockageHasBeenIndicated(
119 content_setting_image_model_->get_content_settings_type()); 114 content_setting_image_model_->get_content_settings_type());
120 } 115 }
121 116
122 void ContentSettingImageView::AnimationEnded(const ui::Animation* animation) { 117 void ContentSettingImageView::AnimationEnded(const ui::Animation* animation) {
123 slide_animator_.Reset(); 118 slide_animator_.Reset();
124 if (!pause_animation_) { 119 if (!pause_animation_) {
125 SetLayoutManager(new views::BoxLayout( 120 text_label_->SetVisible(false);
126 views::BoxLayout::kHorizontal, 0, 0, 0));
127 RemoveChildView(text_label_); // will also delete the view.
128 text_label_ = NULL;
129 parent_->Layout(); 121 parent_->Layout();
130 parent_->SchedulePaint(); 122 parent_->SchedulePaint();
131 } 123 }
132 } 124 }
133 125
134 void ContentSettingImageView::AnimationProgressed( 126 void ContentSettingImageView::AnimationProgressed(
135 const ui::Animation* animation) { 127 const ui::Animation* animation) {
136 if (!pause_animation_) { 128 if (!pause_animation_) {
137 parent_->Layout(); 129 parent_->Layout();
138 parent_->SchedulePaint(); 130 parent_->SchedulePaint();
139 } 131 }
140 } 132 }
141 133
142 void ContentSettingImageView::AnimationCanceled( 134 void ContentSettingImageView::AnimationCanceled(
143 const ui::Animation* animation) { 135 const ui::Animation* animation) {
144 AnimationEnded(animation); 136 AnimationEnded(animation);
145 } 137 }
146 138
147 gfx::Size ContentSettingImageView::GetPreferredSize() { 139 gfx::Size ContentSettingImageView::GetPreferredSize() {
148 // Height will be ignored by the LocationBarView. 140 // Height will be ignored by the LocationBarView.
149 gfx::Size preferred_size(views::View::GetPreferredSize()); 141 gfx::Size size(icon_->GetPreferredSize());
150 int non_label_width = preferred_size.width() -
151 (text_label_ ? text_label_->GetPreferredSize().width() : 0);
152
153 int visible_text_size = 0;
154 if (background_showing()) { 142 if (background_showing()) {
155 double state = slide_animator_.GetCurrentValue(); 143 double state = slide_animator_.GetCurrentValue();
156 // The fraction of the animation we'll spend animating the string into view, 144 // The fraction of the animation we'll spend animating the string into view,
157 // which is also the fraction we'll spend animating it closed; total 145 // which is also the fraction we'll spend animating it closed; total
158 // animation (slide out, show, then slide in) is 1.0. 146 // animation (slide out, show, then slide in) is 1.0.
159 const double kOpenFraction = 147 const double kOpenFraction =
160 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS; 148 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS;
161 double size_fraction = 1.0; 149 double size_fraction = 1.0;
162 if (state < kOpenFraction) 150 if (state < kOpenFraction)
163 size_fraction = state / kOpenFraction; 151 size_fraction = state / kOpenFraction;
164 if (state > (1.0 - kOpenFraction)) 152 if (state > (1.0 - kOpenFraction))
165 size_fraction = (1.0 - state) / kOpenFraction; 153 size_fraction = (1.0 - state) / kOpenFraction;
166 visible_text_size = size_fraction * text_size_; 154 size.Enlarge(
155 size_fraction * (text_label_->GetPreferredSize().width() +
156 GetTotalSpacingWhileAnimating()), 0);
157 size.ClampToMin(background_painter_->GetMinimumSize());
167 } 158 }
159 return size;
160 }
168 161
169 preferred_size.set_width(non_label_width + visible_text_size); 162 void ContentSettingImageView::Layout() {
sky 2013/05/29 23:37:47 Does this do the right thing with rtl?
Peter Kasting 2013/05/29 23:54:52 It seems to. I assume this is because views auto-
170 return preferred_size; 163 const int icon_width = icon_->GetPreferredSize().width();
164 icon_->SetBounds(
165 std::min((width() - icon_width) / 2, kHorizMargin), 0,
166 icon_width, height());
167 text_label_->SetBounds(
168 icon_->bounds().right() + kIconLabelSpacing, 0,
169 std::max(width() - GetTotalSpacingWhileAnimating() - icon_width, 0),
170 text_label_->GetPreferredSize().height());
171 } 171 }
172 172
173 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { 173 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) {
174 // We want to show the bubble on mouse release; that is the standard behavior 174 // We want to show the bubble on mouse release; that is the standard behavior
175 // for buttons. 175 // for buttons.
176 return true; 176 return true;
177 } 177 }
178 178
179 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) { 179 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) {
180 if (HitTestPoint(event.location())) 180 if (HitTestPoint(event.location()))
(...skipping 18 matching lines...) Expand all
199 bubble_widget_->RemoveObserver(this); 199 bubble_widget_->RemoveObserver(this);
200 bubble_widget_ = NULL; 200 bubble_widget_ = NULL;
201 201
202 if (pause_animation_) { 202 if (pause_animation_) {
203 slide_animator_.Reset(pause_animation_state_); 203 slide_animator_.Reset(pause_animation_state_);
204 pause_animation_ = false; 204 pause_animation_ = false;
205 slide_animator_.Show(); 205 slide_animator_.Show();
206 } 206 }
207 } 207 }
208 208
209 int ContentSettingImageView::GetTotalSpacingWhileAnimating() const {
210 return kHorizMargin * 2 + kIconLabelSpacing;
Peter Kasting 2013/05/29 22:00:02 Forgot to comment on this -- this function will be
211 }
212
209 void ContentSettingImageView::OnClick() { 213 void ContentSettingImageView::OnClick() {
210 if (slide_animator_.is_animating()) { 214 if (slide_animator_.is_animating()) {
211 if (!pause_animation_) { 215 if (!pause_animation_) {
212 pause_animation_ = true; 216 pause_animation_ = true;
213 pause_animation_state_ = slide_animator_.GetCurrentValue(); 217 pause_animation_state_ = slide_animator_.GetCurrentValue();
214 } 218 }
215 slide_animator_.Reset(); 219 slide_animator_.Reset();
216 } 220 }
217 221
218 content::WebContents* web_contents = parent_->GetWebContents(); 222 content::WebContents* web_contents = parent_->GetWebContents();
219 if (web_contents && !bubble_widget_) { 223 if (web_contents && !bubble_widget_) {
220 bubble_widget_ = 224 bubble_widget_ =
221 parent_->delegate()->CreateViewsBubble(new ContentSettingBubbleContents( 225 parent_->delegate()->CreateViewsBubble(new ContentSettingBubbleContents(
222 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 226 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
223 parent_->delegate()->GetContentSettingBubbleModelDelegate(), 227 parent_->delegate()->GetContentSettingBubbleModelDelegate(),
224 web_contents, parent_->profile(), 228 web_contents, parent_->profile(),
225 content_setting_image_model_->get_content_settings_type()), 229 content_setting_image_model_->get_content_settings_type()),
226 web_contents, this, views::BubbleBorder::TOP_RIGHT)); 230 web_contents, this, views::BubbleBorder::TOP_RIGHT));
227 bubble_widget_->AddObserver(this); 231 bubble_widget_->AddObserver(this);
228 bubble_widget_->Show(); 232 bubble_widget_->Show();
229 } 233 }
230 } 234 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/content_setting_image_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698