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

Side by Side Diff: chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc

Issue 5023001: Handful of related instant changes: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix linux build Created 10 years, 1 month 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/views/autocomplete/autocomplete_popup_contents_view.h" 5 #include "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h"
6 6
7 #include "app/bidi_line_iterator.h" 7 #include "app/bidi_line_iterator.h"
8 #include "app/l10n_util.h" 8 #include "app/l10n_util.h"
9 #include "app/resource_bundle.h" 9 #include "app/resource_bundle.h"
10 #include "app/theme_provider.h" 10 #include "app/theme_provider.h"
11 #include "app/text_elider.h" 11 #include "app/text_elider.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/i18n/rtl.h" 13 #include "base/i18n/rtl.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" 15 #include "chrome/browser/autocomplete/autocomplete_edit_view.h"
16 #include "chrome/browser/autocomplete/autocomplete_match.h" 16 #include "chrome/browser/autocomplete/autocomplete_match.h"
17 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" 17 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
18 #include "chrome/browser/instant/instant_opt_in.h" 18 #include "chrome/browser/instant/instant_confirm_dialog.h"
19 #include "chrome/browser/instant/promo_counter.h"
20 #include "chrome/browser/profile.h"
19 #include "chrome/browser/views/bubble_border.h" 21 #include "chrome/browser/views/bubble_border.h"
20 #include "chrome/browser/views/location_bar/location_bar_view.h" 22 #include "chrome/browser/views/location_bar/location_bar_view.h"
21 #include "gfx/canvas_skia.h" 23 #include "gfx/canvas_skia.h"
22 #include "gfx/color_utils.h" 24 #include "gfx/color_utils.h"
23 #include "gfx/insets.h" 25 #include "gfx/insets.h"
24 #include "gfx/path.h" 26 #include "gfx/path.h"
25 #include "grit/chromium_strings.h" 27 #include "grit/chromium_strings.h"
26 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
27 #include "grit/theme_resources.h" 29 #include "grit/theme_resources.h"
28 #include "third_party/skia/include/core/SkShader.h" 30 #include "third_party/skia/include/core/SkShader.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 #else 126 #else
125 // Don't adjust font on chromeos as it becomes too small. 127 // Don't adjust font on chromeos as it becomes too small.
126 const int kEditFontAdjust = 0; 128 const int kEditFontAdjust = 0;
127 #endif 129 #endif
128 130
129 // Horizontal padding between the buttons on the opt in promo. 131 // Horizontal padding between the buttons on the opt in promo.
130 const int kOptInButtonPadding = 2; 132 const int kOptInButtonPadding = 2;
131 133
132 // Padding around the opt in view. 134 // Padding around the opt in view.
133 const int kOptInLeftPadding = 12; 135 const int kOptInLeftPadding = 12;
134 const int kOptInRightPadding = 6; 136 const int kOptInRightPadding = 10;
135 const int kOptInTopPadding = 6; 137 const int kOptInTopPadding = 6;
136 const int kOptInBottomPadding = 3; 138 const int kOptInBottomPadding = 5;
137 139
138 // Padding between the top of the opt-in view and the separator. 140 // Horizontal/Vertical inset of the promo background.
139 const int kOptInSeparatorSpacing = 2; 141 const int kOptInBackgroundHInset = 6;
142 const int kOptInBackgroundVInset = 2;
140 143
141 // Border for instant opt-in buttons. Consists of two 9 patch painters: one for 144 // Border for instant opt-in buttons. Consists of two 9 patch painters: one for
142 // the normal state, the other for the pressed state. 145 // the normal state, the other for the pressed state.
143 class OptInButtonBorder : public views::Border { 146 class OptInButtonBorder : public views::Border {
144 public: 147 public:
145 OptInButtonBorder() { 148 OptInButtonBorder() {
146 border_painter_.reset(CreatePainter(IDR_OPT_IN_BUTTON)); 149 border_painter_.reset(CreatePainter(IDR_OPT_IN_BUTTON));
147 border_pushed_painter_.reset(CreatePainter(IDR_OPT_IN_BUTTON_P)); 150 border_pushed_painter_.reset(CreatePainter(IDR_OPT_IN_BUTTON_P));
148 } 151 }
149 152
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 188
186 } // namespace 189 } // namespace
187 190
188 class AutocompletePopupContentsView::InstantOptInView 191 class AutocompletePopupContentsView::InstantOptInView
189 : public views::View, 192 : public views::View,
190 public views::ButtonListener { 193 public views::ButtonListener {
191 public: 194 public:
192 InstantOptInView(AutocompletePopupContentsView* contents_view, 195 InstantOptInView(AutocompletePopupContentsView* contents_view,
193 const gfx::Font& label_font, 196 const gfx::Font& label_font,
194 const gfx::Font& button_font) 197 const gfx::Font& button_font)
195 : contents_view_(contents_view) { 198 : contents_view_(contents_view),
199 bg_painter_(views::Painter::CreateVerticalGradient(
200 SkColorSetRGB(255, 242, 183),
201 SkColorSetRGB(250, 230, 145))) {
196 views::Label* label = 202 views::Label* label =
197 new views::Label(l10n_util::GetString(IDS_INSTANT_OPT_IN_LABEL)); 203 new views::Label(l10n_util::GetString(IDS_INSTANT_OPT_IN_LABEL));
198 label->SetFont(label_font); 204 label->SetFont(label_font);
199 205
200 views::GridLayout* layout = new views::GridLayout(this); 206 views::GridLayout* layout = new views::GridLayout(this);
201 layout->SetInsets(kOptInTopPadding, kOptInLeftPadding, 207 layout->SetInsets(kOptInTopPadding, kOptInLeftPadding,
202 kOptInBottomPadding, kOptInRightPadding); 208 kOptInBottomPadding, kOptInRightPadding);
203 SetLayoutManager(layout); 209 SetLayoutManager(layout);
204 210
205 const int first_column_set = 1; 211 const int first_column_set = 1;
(...skipping 14 matching lines...) Expand all
220 layout->AddView(CreateButton(IDS_INSTANT_OPT_IN_NO_THANKS, button_font)); 226 layout->AddView(CreateButton(IDS_INSTANT_OPT_IN_NO_THANKS, button_font));
221 } 227 }
222 228
223 virtual void ButtonPressed(views::Button* sender, const views::Event& event) { 229 virtual void ButtonPressed(views::Button* sender, const views::Event& event) {
224 contents_view_->UserPressedOptIn( 230 contents_view_->UserPressedOptIn(
225 sender->tag() == IDS_INSTANT_OPT_IN_ENABLE); 231 sender->tag() == IDS_INSTANT_OPT_IN_ENABLE);
226 // WARNING: we've been deleted. 232 // WARNING: we've been deleted.
227 } 233 }
228 234
229 virtual void Paint(gfx::Canvas* canvas) { 235 virtual void Paint(gfx::Canvas* canvas) {
230 SkColor line_color = color_utils::AlphaBlend(GetColor(NORMAL, DIMMED_TEXT), 236 canvas->Save();
231 GetColor(NORMAL, BACKGROUND), 237 canvas->TranslateInt(kOptInBackgroundHInset, kOptInBackgroundVInset);
232 48); 238 bg_painter_->Paint(width() - kOptInBackgroundHInset * 2,
233 canvas->DrawLineInt( 239 height() - kOptInBackgroundVInset * 2, canvas);
234 line_color, 0, kOptInSeparatorSpacing, width(), kOptInSeparatorSpacing); 240 canvas->DrawRectInt(ResourceBundle::toolbar_separator_color, 0, 0,
241 width() - kOptInBackgroundHInset * 2,
242 height() - kOptInBackgroundVInset * 2);
243 canvas->Restore();
235 } 244 }
236 245
237 private: 246 private:
238 // Creates and returns a button configured for the opt-in promo. 247 // Creates and returns a button configured for the opt-in promo.
239 views::View* CreateButton(int id, const gfx::Font& font) { 248 views::View* CreateButton(int id, const gfx::Font& font) {
240 // NOTE: we can't use NativeButton as the popup is a layered window and 249 // NOTE: we can't use NativeButton as the popup is a layered window and
241 // native buttons don't draw in layered windows. 250 // native buttons don't draw in layered windows.
242 // TODO: these buttons look crap. Figure out the right border/background to 251 // TODO: these buttons look crap. Figure out the right border/background to
243 // use. 252 // use.
244 views::TextButton* button = 253 views::TextButton* button =
245 new views::TextButton(this, l10n_util::GetString(id)); 254 new views::TextButton(this, l10n_util::GetString(id));
246 button->set_border(new OptInButtonBorder()); 255 button->set_border(new OptInButtonBorder());
247 button->SetNormalHasBorder(true); 256 button->SetNormalHasBorder(true);
248 button->set_tag(id); 257 button->set_tag(id);
249 button->SetFont(font); 258 button->SetFont(font);
250 button->set_animate_on_state_change(false); 259 button->set_animate_on_state_change(false);
251 return button; 260 return button;
252 } 261 }
253 262
254 AutocompletePopupContentsView* contents_view_; 263 AutocompletePopupContentsView* contents_view_;
264 scoped_ptr<views::Painter> bg_painter_;
255 265
256 DISALLOW_COPY_AND_ASSIGN(InstantOptInView); 266 DISALLOW_COPY_AND_ASSIGN(InstantOptInView);
257 }; 267 };
258 268
259 class AutocompleteResultView : public views::View { 269 class AutocompleteResultView : public views::View {
260 public: 270 public:
261 AutocompleteResultView(AutocompleteResultViewModel* model, 271 AutocompleteResultView(AutocompleteResultViewModel* model,
262 int model_index, 272 int model_index,
263 const gfx::Font& font, 273 const gfx::Font& font,
264 const gfx::Font& bold_font); 274 const gfx::Font& bold_font);
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 } else { 852 } else {
843 result_view = static_cast<AutocompleteResultView*>(GetChildViewAt(i)); 853 result_view = static_cast<AutocompleteResultView*>(GetChildViewAt(i));
844 result_view->SetVisible(true); 854 result_view->SetVisible(true);
845 } 855 }
846 result_view->set_match(GetMatchAtIndex(i)); 856 result_view->set_match(GetMatchAtIndex(i));
847 total_child_height += result_view->GetPreferredSize().height(); 857 total_child_height += result_view->GetPreferredSize().height();
848 } 858 }
849 for (size_t i = model_->result().size(); i < child_rv_count; ++i) 859 for (size_t i = model_->result().size(); i < child_rv_count; ++i)
850 GetChildViewAt(i)->SetVisible(false); 860 GetChildViewAt(i)->SetVisible(false);
851 861
852 if (!opt_in_view_ && browser::ShouldShowInstantOptIn(model_->profile())) { 862 PromoCounter* counter = model_->profile()->GetInstantPromoCounter();
863 if (!opt_in_view_ && counter && counter->ShouldShow(base::Time::Now())) {
853 opt_in_view_ = new InstantOptInView(this, result_bold_font_, result_font_); 864 opt_in_view_ = new InstantOptInView(this, result_bold_font_, result_font_);
854 AddChildView(opt_in_view_); 865 AddChildView(opt_in_view_);
866 } else if (opt_in_view_ && (!counter ||
867 !counter->ShouldShow(base::Time::Now()))) {
868 delete opt_in_view_;
869 opt_in_view_ = NULL;
855 } 870 }
856 871
857 if (opt_in_view_) 872 if (opt_in_view_)
858 total_child_height += opt_in_view_->GetPreferredSize().height(); 873 total_child_height += opt_in_view_->GetPreferredSize().height();
859 874
860 gfx::Rect new_target_bounds = CalculateTargetBounds(total_child_height); 875 gfx::Rect new_target_bounds = CalculateTargetBounds(total_child_height);
861 876
862 // If we're animating and our target height changes, reset the animation. 877 // If we're animating and our target height changes, reset the animation.
863 // NOTE: If we just reset blindly on _every_ update, then when the user types 878 // NOTE: If we just reset blindly on _every_ update, then when the user types
864 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the 879 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 gfx::Point location_bar_origin(location_bar_bounds.origin()); 1193 gfx::Point location_bar_origin(location_bar_bounds.origin());
1179 views::View::ConvertPointToScreen(location_bar_, &location_bar_origin); 1194 views::View::ConvertPointToScreen(location_bar_, &location_bar_origin);
1180 location_bar_bounds.set_origin(location_bar_origin); 1195 location_bar_bounds.set_origin(location_bar_origin);
1181 return bubble_border_->GetBounds( 1196 return bubble_border_->GetBounds(
1182 location_bar_bounds, gfx::Size(location_bar_bounds.width(), h)); 1197 location_bar_bounds, gfx::Size(location_bar_bounds.width(), h));
1183 } 1198 }
1184 1199
1185 void AutocompletePopupContentsView::UserPressedOptIn(bool opt_in) { 1200 void AutocompletePopupContentsView::UserPressedOptIn(bool opt_in) {
1186 delete opt_in_view_; 1201 delete opt_in_view_;
1187 opt_in_view_ = NULL; 1202 opt_in_view_ = NULL;
1188 browser::UserPickedInstantOptIn(location_bar_->GetWindow()->GetNativeWindow(), 1203 PromoCounter* counter = model_->profile()->GetInstantPromoCounter();
1189 model_->profile(), opt_in); 1204 DCHECK(counter);
1205 counter->Hide();
1206 if (opt_in) {
1207 browser::ShowInstantConfirmDialogIfNecessary(
1208 location_bar_->GetWindow()->GetNativeWindow(), model_->profile());
1209 }
1190 UpdatePopupAppearance(); 1210 UpdatePopupAppearance();
1191 } 1211 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url_model.cc ('k') | chrome/browser/ui/views/infobars/infobars.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698