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

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

Issue 8113031: Change std::wstring to string16 for views::Label and views::Link (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 2 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/autocomplete/autocomplete_popup_contents_view. h" 5 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view. h"
6 6
7 #if defined(OS_WIN)
8 #include <commctrl.h>
9 #include <dwmapi.h>
10 #include <objidl.h>
11 #endif
12
7 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
8 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" 15 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
10 #include "chrome/browser/instant/instant_confirm_dialog.h" 16 #include "chrome/browser/instant/instant_confirm_dialog.h"
11 #include "chrome/browser/instant/promo_counter.h" 17 #include "chrome/browser/instant/promo_counter.h"
12 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/omnibox/omnibox_view.h" 19 #include "chrome/browser/ui/omnibox/omnibox_view.h"
14 #include "chrome/browser/ui/views/autocomplete/autocomplete_result_view.h" 20 #include "chrome/browser/ui/views/autocomplete/autocomplete_result_view.h"
15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 21 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
16 #include "grit/chromium_strings.h" 22 #include "grit/chromium_strings.h"
17 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
18 #include "grit/theme_resources.h" 24 #include "grit/theme_resources.h"
19 #include "third_party/skia/include/core/SkShader.h" 25 #include "third_party/skia/include/core/SkShader.h"
20 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/base/theme_provider.h" 28 #include "ui/base/theme_provider.h"
23 #include "ui/gfx/canvas_skia.h" 29 #include "ui/gfx/canvas_skia.h"
24 #include "ui/gfx/insets.h" 30 #include "ui/gfx/insets.h"
25 #include "ui/gfx/path.h" 31 #include "ui/gfx/path.h"
26 #include "unicode/ubidi.h" 32 #include "unicode/ubidi.h"
27 #include "views/bubble/bubble_border.h" 33 #include "views/bubble/bubble_border.h"
28 #include "views/controls/button/text_button.h" 34 #include "views/controls/button/text_button.h"
29 #include "views/controls/label.h" 35 #include "views/controls/label.h"
30 #include "views/layout/grid_layout.h" 36 #include "views/layout/grid_layout.h"
31 #include "views/layout/layout_constants.h" 37 #include "views/layout/layout_constants.h"
32 #include "views/painter.h" 38 #include "views/painter.h"
33 #include "views/widget/widget.h" 39 #include "views/widget/widget.h"
34 40
35 #if defined(OS_WIN) 41 #if defined(OS_WIN)
36 #include <commctrl.h>
37 #include <dwmapi.h>
38 #include <objidl.h>
39
40 #include "base/win/scoped_gdi_object.h" 42 #include "base/win/scoped_gdi_object.h"
41 #if !defined(USE_AURA) 43 #if !defined(USE_AURA)
42 #include "views/widget/native_widget_win.h" 44 #include "views/widget/native_widget_win.h"
43 #endif 45 #endif
44 #endif 46 #endif
45 47
46 #if defined(TOOLKIT_USES_GTK) 48 #if defined(TOOLKIT_USES_GTK)
47 #include "ui/gfx/skia_utils_gtk.h" 49 #include "ui/gfx/skia_utils_gtk.h"
48 #endif 50 #endif
49 51
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } // namespace 143 } // namespace
142 144
143 class AutocompletePopupContentsView::AutocompletePopupWidget 145 class AutocompletePopupContentsView::AutocompletePopupWidget
144 : public views::Widget, 146 : public views::Widget,
145 public base::SupportsWeakPtr<AutocompletePopupWidget> { 147 public base::SupportsWeakPtr<AutocompletePopupWidget> {
146 public: 148 public:
147 AutocompletePopupWidget() {} 149 AutocompletePopupWidget() {}
148 virtual ~AutocompletePopupWidget() {} 150 virtual ~AutocompletePopupWidget() {}
149 151
150 private: 152 private:
151 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupWidget); 153 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupWidget);
152 }; 154 };
153 155
154 class AutocompletePopupContentsView::InstantOptInView 156 class AutocompletePopupContentsView::InstantOptInView
155 : public views::View, 157 : public views::View,
156 public views::ButtonListener { 158 public views::ButtonListener {
157 public: 159 public:
158 InstantOptInView(AutocompletePopupContentsView* contents_view, 160 InstantOptInView(AutocompletePopupContentsView* contents_view,
159 const gfx::Font& label_font, 161 const gfx::Font& label_font,
160 const gfx::Font& button_font) 162 const gfx::Font& button_font)
161 : contents_view_(contents_view), 163 : contents_view_(contents_view),
162 bg_painter_(views::Painter::CreateVerticalGradient( 164 bg_painter_(views::Painter::CreateVerticalGradient(
163 SkColorSetRGB(255, 242, 183), 165 SkColorSetRGB(255, 242, 183),
164 SkColorSetRGB(250, 230, 145))) { 166 SkColorSetRGB(250, 230, 145))) {
165 views::Label* label = new views::Label( 167 views::Label* label = new views::Label(
166 UTF16ToWide(l10n_util::GetStringUTF16(IDS_INSTANT_OPT_IN_LABEL))); 168 l10n_util::GetStringUTF16(IDS_INSTANT_OPT_IN_LABEL));
167 label->SetFont(label_font); 169 label->SetFont(label_font);
168 170
169 views::GridLayout* layout = new views::GridLayout(this); 171 views::GridLayout* layout = new views::GridLayout(this);
170 layout->SetInsets(kOptInTopPadding, kOptInLeftPadding, 172 layout->SetInsets(kOptInTopPadding, kOptInLeftPadding,
171 kOptInBottomPadding, kOptInRightPadding); 173 kOptInBottomPadding, kOptInRightPadding);
172 SetLayoutManager(layout); 174 SetLayoutManager(layout);
173 175
174 const int first_column_set = 1; 176 const int first_column_set = 1;
175 views::GridLayout::Alignment v_align = views::GridLayout::CENTER; 177 views::GridLayout::Alignment v_align = views::GridLayout::CENTER;
176 views::ColumnSet* column_set = layout->AddColumnSet(first_column_set); 178 views::ColumnSet* column_set = layout->AddColumnSet(first_column_set);
(...skipping 27 matching lines...) Expand all
204 width() - kOptInBackgroundHInset * 2, 206 width() - kOptInBackgroundHInset * 2,
205 height() - kOptInBackgroundVInset * 2); 207 height() - kOptInBackgroundVInset * 2);
206 canvas->Restore(); 208 canvas->Restore();
207 } 209 }
208 210
209 private: 211 private:
210 // Creates and returns a button configured for the opt-in promo. 212 // Creates and returns a button configured for the opt-in promo.
211 views::View* CreateButton(int id, const gfx::Font& font) { 213 views::View* CreateButton(int id, const gfx::Font& font) {
212 // NOTE: we can't use NativeButton as the popup is a layered window and 214 // NOTE: we can't use NativeButton as the popup is a layered window and
213 // native buttons don't draw in layered windows. 215 // native buttons don't draw in layered windows.
214 // TODO: these buttons look crap. Figure out the right border/background to 216 // TODO(sky): these buttons look crap. Figure out the right
215 // use. 217 // border/background to use.
216 views::TextButton* button = 218 views::TextButton* button =
217 new views::TextButton(this, UTF16ToWide(l10n_util::GetStringUTF16(id))); 219 new views::TextButton(this, UTF16ToWide(l10n_util::GetStringUTF16(id)));
218 button->set_border(new OptInButtonBorder()); 220 button->set_border(new OptInButtonBorder());
219 button->set_tag(id); 221 button->set_tag(id);
220 button->SetFont(font); 222 button->SetFont(font);
221 button->set_animate_on_state_change(false); 223 button->set_animate_on_state_change(false);
222 return button; 224 return button;
223 } 225 }
224 226
225 AutocompletePopupContentsView* contents_view_; 227 AutocompletePopupContentsView* contents_view_;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 popup_->Close(); // This will eventually delete the popup. 315 popup_->Close(); // This will eventually delete the popup.
314 popup_.reset(); 316 popup_.reset();
315 } 317 }
316 return; 318 return;
317 } 319 }
318 320
319 // Update the match cached by each row, in the process of doing so make sure 321 // Update the match cached by each row, in the process of doing so make sure
320 // we have enough row views. 322 // we have enough row views.
321 size_t child_rv_count = child_count(); 323 size_t child_rv_count = child_count();
322 if (opt_in_view_) { 324 if (opt_in_view_) {
323 DCHECK(child_rv_count > 0); 325 DCHECK_GT(child_rv_count, 0u);
324 child_rv_count--; 326 child_rv_count--;
325 } 327 }
326 for (size_t i = 0; i < model_->result().size(); ++i) { 328 for (size_t i = 0; i < model_->result().size(); ++i) {
327 AutocompleteResultView* result_view; 329 AutocompleteResultView* result_view;
328 if (i >= child_rv_count) { 330 if (i >= child_rv_count) {
329 result_view = 331 result_view =
330 CreateResultView(this, i, result_font_, result_bold_font_); 332 CreateResultView(this, i, result_font_, result_bold_font_);
331 AddChildViewAt(result_view, static_cast<int>(i)); 333 AddChildViewAt(result_view, static_cast<int>(i));
332 } else { 334 } else {
333 result_view = static_cast<AutocompleteResultView*>(child_at(i)); 335 result_view = static_cast<AutocompleteResultView*>(child_at(i));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 params.transparent = true; 368 params.transparent = true;
367 params.parent_widget = location_bar_->GetWidget(); 369 params.parent_widget = location_bar_->GetWidget();
368 params.bounds = GetPopupBounds(); 370 params.bounds = GetPopupBounds();
369 popup_->Init(params); 371 popup_->Init(params);
370 popup_->SetContentsView(this); 372 popup_->SetContentsView(this);
371 popup_->MoveAbove( 373 popup_->MoveAbove(
372 GetRelativeWindowForPopup(omnibox_view_->GetNativeView())); 374 GetRelativeWindowForPopup(omnibox_view_->GetNativeView()));
373 if (!popup_.get()) { 375 if (!popup_.get()) {
374 // For some IMEs GetRelativeWindowForPopup triggers the omnibox to lose 376 // For some IMEs GetRelativeWindowForPopup triggers the omnibox to lose
375 // focus, thereby closing (and destroying) the popup. 377 // focus, thereby closing (and destroying) the popup.
376 // TODO: this won't be needed once we close the omnibox on input window 378 // TODO(sky): this won't be needed once we close the omnibox on input
377 // showing. 379 // window showing.
378 return; 380 return;
379 } 381 }
380 popup_->Show(); 382 popup_->Show();
381 } else { 383 } else {
382 // Animate the popup shrinking, but don't animate growing larger since that 384 // Animate the popup shrinking, but don't animate growing larger since that
383 // would make the popup feel less responsive. 385 // would make the popup feel less responsive.
384 start_bounds_ = GetWidget()->GetWindowScreenBounds(); 386 start_bounds_ = GetWidget()->GetWindowScreenBounds();
385 if (target_bounds_.height() < start_bounds_.height()) 387 if (target_bounds_.height() < start_bounds_.height())
386 size_animation_.Show(); 388 size_animation_.Show();
387 else 389 else
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 opt_in_view_ = NULL; 712 opt_in_view_ = NULL;
711 PromoCounter* counter = profile_->GetInstantPromoCounter(); 713 PromoCounter* counter = profile_->GetInstantPromoCounter();
712 DCHECK(counter); 714 DCHECK(counter);
713 counter->Hide(); 715 counter->Hide();
714 if (opt_in) { 716 if (opt_in) {
715 browser::ShowInstantConfirmDialogIfNecessary( 717 browser::ShowInstantConfirmDialogIfNecessary(
716 location_bar_->GetWidget()->GetNativeWindow(), profile_); 718 location_bar_->GetWidget()->GetNativeWindow(), profile_);
717 } 719 }
718 UpdatePopupAppearance(); 720 UpdatePopupAppearance();
719 } 721 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/about_chrome_view.cc ('k') | chrome/browser/ui/views/avatar_menu_bubble_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698