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

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

Issue 200009: Use system themes where possible in Omnibox, dropdown, and security info bubb... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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/toolbar_model.cc ('k') | chrome/browser/views/info_bubble.cc » ('j') | 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) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // 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/gfx/canvas.h" 7 #include "app/gfx/canvas.h"
8 #include "app/gfx/color_utils.h" 8 #include "app/gfx/color_utils.h"
9 #include "app/gfx/insets.h" 9 #include "app/gfx/insets.h"
10 #include "app/gfx/path.h" 10 #include "app/gfx/path.h"
(...skipping 10 matching lines...) Expand all
21 #include "views/widget/widget.h" 21 #include "views/widget/widget.h"
22 22
23 #if defined(OS_WIN) 23 #if defined(OS_WIN)
24 #include <objidl.h> 24 #include <objidl.h>
25 #include <commctrl.h> 25 #include <commctrl.h>
26 #include <dwmapi.h> 26 #include <dwmapi.h>
27 27
28 #include "app/win_util.h" 28 #include "app/win_util.h"
29 #endif 29 #endif
30 30
31 // Colors for various components of the view. 31 namespace {
32
33 enum ResultViewState {
34 NORMAL = 0,
35 SELECTED,
36 HOVERED,
37 NUM_STATES
38 };
39
40 enum ColorKind {
41 BACKGROUND = 0,
42 TEXT,
43 DIMMED_TEXT,
44 URL,
45 NUM_KINDS
46 };
47
48 SkColor GetColor(ResultViewState state, ColorKind kind) {
49 static bool initialized = false;
50 static SkColor colors[NUM_STATES][NUM_KINDS];
51 if (!initialized) {
32 #if defined(OS_WIN) 52 #if defined(OS_WIN)
33 static const SkColor kBackgroundColor = 53 colors[NORMAL][BACKGROUND] = color_utils::GetSysSkColor(COLOR_WINDOW);
34 color_utils::GetSysSkColor(COLOR_WINDOW); 54 colors[SELECTED][BACKGROUND] = color_utils::GetSysSkColor(COLOR_HIGHLIGHT);
35 static const SkColor kSelectedBackgroundColor = 55 colors[NORMAL][TEXT] = color_utils::GetSysSkColor(COLOR_WINDOWTEXT);
36 color_utils::GetSysSkColor(COLOR_HIGHLIGHT); 56 colors[SELECTED][TEXT] = color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT);
37 static const SkColor kHoverBackgroundColor =
38 SkColorSetA(kSelectedBackgroundColor, 127);
39 static const SkColor kTextColor =
40 color_utils::GetSysSkColor(COLOR_WINDOWTEXT);
41 static const SkColor kSelectedTextColor =
42 color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT);
43 static const SkColor kDimTextColor =
44 color_utils::GetSysSkColor(COLOR_GRAYTEXT);
45 static const SkColor kSelectedDimTextColor =
46 color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT);
47 #else 57 #else
48 // TODO(beng): source from theme provider. 58 // TODO(beng): source from theme provider.
49 static const SkColor kBackgroundColor = SK_ColorWHITE; 59 colors[NORMAL][BACKGROUND] = SK_ColorWHITE;
50 static const SkColor kSelectedBackgroundColor = SK_ColorBLUE; 60 colors[SELECTED][BACKGROUND] = SK_ColorBLUE;
51 static const SkColor kHoverBackgroundColor = SK_ColorCYAN; 61 colors[NORMAL][TEXT] = SK_ColorBLACK;
52 static const SkColor kTextColor = SK_ColorBLACK; 62 colors[SELECTED][TEXT] = SK_ColorWHITE;
53 static const SkColor kSelectedTextColor = SK_ColorWHITE;
54 static const SkColor kDimTextColor = SK_ColorGRAY;
55 static const SkColor kSelectedDimTextColor = SK_ColorWHITE;
56 #endif 63 #endif
57 static const SkColor kStandardURLColor = SkColorSetRGB(0, 0x80, 0); 64 colors[HOVERED][BACKGROUND] =
58 static const SkColor kHighlightURLColor = SkColorSetRGB(0xD0, 0xFF, 0xD0); 65 color_utils::AlphaBlend(colors[SELECTED][BACKGROUND],
59 static const int kGlassPopupTransparency = 240; 66 colors[NORMAL][BACKGROUND], 64);
60 static const int kOpaquePopupTransparency = 255; 67 colors[HOVERED][TEXT] = colors[NORMAL][TEXT];
61 static const int kHoverRowAlpha = 0x40; 68 const SkColor kDarkURL = SkColorSetRGB(0, 128, 0);
69 const SkColor kLightURL = SkColorSetRGB(128, 255, 128);
70 for (int i = 0; i < NUM_STATES; ++i) {
71 colors[i][DIMMED_TEXT] =
72 color_utils::AlphaBlend(colors[i][TEXT], colors[i][BACKGROUND], 128);
73 colors[i][URL] = color_utils::PickMoreReadableColor(kDarkURL, kLightURL,
74 colors[i][BACKGROUND]);
75 }
76 initialized = true;
77 }
78
79 return colors[state][kind];
80 }
81
82 const SkAlpha kGlassPopupAlpha = 240;
83 const SkAlpha kOpaquePopupAlpha = 255;
62 // The minimum distance between the top and bottom of the icon and the top or 84 // The minimum distance between the top and bottom of the icon and the top or
63 // bottom of the row. "Minimum" is used because the vertical padding may be 85 // bottom of the row. "Minimum" is used because the vertical padding may be
64 // larger, depending on the size of the text. 86 // larger, depending on the size of the text.
65 static const int kIconVerticalPadding = 2; 87 const int kIconVerticalPadding = 2;
66 // The minimum distance between the top and bottom of the text and the top or 88 // The minimum distance between the top and bottom of the text and the top or
67 // bottom of the row. See comment about the use of "minimum" for 89 // bottom of the row. See comment about the use of "minimum" for
68 // kIconVerticalPadding. 90 // kIconVerticalPadding.
69 static const int kTextVerticalPadding = 3; 91 const int kTextVerticalPadding = 3;
70 // The padding at the left edge of the row, left of the icon. 92 // The padding at the left edge of the row, left of the icon.
71 static const int kRowLeftPadding = 6; 93 const int kRowLeftPadding = 6;
72 // The padding on the right edge of the row, right of the text. 94 // The padding on the right edge of the row, right of the text.
73 static const int kRowRightPadding = 3; 95 const int kRowRightPadding = 3;
74 // The horizontal distance between the right edge of the icon and the left edge 96 // The horizontal distance between the right edge of the icon and the left edge
75 // of the text. 97 // of the text.
76 static const int kIconTextSpacing = 9; 98 const int kIconTextSpacing = 9;
77 // The size delta between the font used for the edit and the result rows. Passed 99 // The size delta between the font used for the edit and the result rows. Passed
78 // to gfx::Font::DeriveFont. 100 // to gfx::Font::DeriveFont.
79 static const int kEditFontAdjust = -1; 101 const int kEditFontAdjust = -1;
102
103 }
80 104
81 class AutocompleteResultView : public views::View { 105 class AutocompleteResultView : public views::View {
82 public: 106 public:
83 AutocompleteResultView(AutocompleteResultViewModel* model, 107 AutocompleteResultView(AutocompleteResultViewModel* model,
84 int model_index, 108 int model_index,
85 const gfx::Font& font); 109 const gfx::Font& font);
86 virtual ~AutocompleteResultView(); 110 virtual ~AutocompleteResultView();
87 111
88 // Updates the match used to paint the contents of this result view. We copy 112 // Updates the match used to paint the contents of this result view. We copy
89 // the match so that we can continue to paint the last result even after the 113 // the match so that we can continue to paint the last result even after the
90 // model has changed. 114 // model has changed.
91 void set_match(const AutocompleteMatch& match) { match_ = match; } 115 void set_match(const AutocompleteMatch& match) { match_ = match; }
92 116
93 // Overridden from views::View: 117 // Overridden from views::View:
94 virtual void Paint(gfx::Canvas* canvas); 118 virtual void Paint(gfx::Canvas* canvas);
95 virtual void Layout(); 119 virtual void Layout();
96 virtual gfx::Size GetPreferredSize(); 120 virtual gfx::Size GetPreferredSize();
97 virtual void OnMouseEntered(const views::MouseEvent& event); 121 virtual void OnMouseEntered(const views::MouseEvent& event);
98 virtual void OnMouseMoved(const views::MouseEvent& event); 122 virtual void OnMouseMoved(const views::MouseEvent& event);
99 virtual void OnMouseExited(const views::MouseEvent& event); 123 virtual void OnMouseExited(const views::MouseEvent& event);
100 virtual bool OnMousePressed(const views::MouseEvent& event); 124 virtual bool OnMousePressed(const views::MouseEvent& event);
101 virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled); 125 virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled);
102 virtual bool OnMouseDragged(const views::MouseEvent& event); 126 virtual bool OnMouseDragged(const views::MouseEvent& event);
103 127
104 private: 128 private:
105 // Get colors for row backgrounds and text for different row states. 129 ResultViewState GetState() const;
106 SkColor GetBackgroundColor() const;
107 SkColor GetTextColor() const;
108 130
109 SkBitmap* GetIcon() const; 131 SkBitmap* GetIcon() const;
110 132
111 // Draws the specified |text| into the canvas, using highlighting provided by 133 // Draws the specified |text| into the canvas, using highlighting provided by
112 // |classifications|. If |force_dim| is true, ACMatchClassification::DIM is 134 // |classifications|. If |force_dim| is true, ACMatchClassification::DIM is
113 // added to all of the classifications. Returns the x position to the right 135 // added to all of the classifications. Returns the x position to the right
114 // of the string. 136 // of the string.
115 int DrawString(gfx::Canvas* canvas, 137 int DrawString(gfx::Canvas* canvas,
116 const std::wstring& text, 138 const std::wstring& text,
117 const ACMatchClassifications& classifications, 139 const ACMatchClassifications& classifications,
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 mirroring_context_(new MirroringContext()), 320 mirroring_context_(new MirroringContext()),
299 match_(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED) { 321 match_(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED) {
300 CHECK(model_index >= 0); 322 CHECK(model_index >= 0);
301 InitClass(); 323 InitClass();
302 } 324 }
303 325
304 AutocompleteResultView::~AutocompleteResultView() { 326 AutocompleteResultView::~AutocompleteResultView() {
305 } 327 }
306 328
307 void AutocompleteResultView::Paint(gfx::Canvas* canvas) { 329 void AutocompleteResultView::Paint(gfx::Canvas* canvas) {
308 canvas->FillRectInt(GetBackgroundColor(), 0, 0, width(), height()); 330 const ResultViewState state = GetState();
331 if (state != NORMAL)
332 canvas->drawColor(GetColor(state, BACKGROUND));
309 333
310 int x = MirroredLeftPointForRect(icon_bounds_); 334 int x = MirroredLeftPointForRect(icon_bounds_);
311 335
312 // Paint the icon. 336 // Paint the icon.
313 canvas->DrawBitmapInt(*GetIcon(), x, icon_bounds_.y()); 337 canvas->DrawBitmapInt(*GetIcon(), x, icon_bounds_.y());
314 338
315 // Paint the text. 339 // Paint the text.
316 // Initialize the |mirroring_context_| with the left and right positions. 340 // Initialize the |mirroring_context_| with the left and right positions.
317 // The DrawString() function uses this |mirroring_context_| to calculate the 341 // The DrawString() function uses this |mirroring_context_| to calculate the
318 // position of an input text. 342 // position of an input text.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 else if (event.IsOnlyLeftMouseButton()) 411 else if (event.IsOnlyLeftMouseButton())
388 model_->OpenIndex(model_index_, CURRENT_TAB); 412 model_->OpenIndex(model_index_, CURRENT_TAB);
389 } 413 }
390 414
391 bool AutocompleteResultView::OnMouseDragged(const views::MouseEvent& event) { 415 bool AutocompleteResultView::OnMouseDragged(const views::MouseEvent& event) {
392 // TODO(beng): move all message handling into the contents view and override 416 // TODO(beng): move all message handling into the contents view and override
393 // GetViewForPoint. 417 // GetViewForPoint.
394 return false; 418 return false;
395 } 419 }
396 420
397 SkColor AutocompleteResultView::GetBackgroundColor() const { 421 ResultViewState AutocompleteResultView::GetState() const {
398 if (model_->IsSelectedIndex(model_index_)) 422 if (model_->IsSelectedIndex(model_index_))
399 return kSelectedBackgroundColor; 423 return SELECTED;
400 return model_->IsHoveredIndex(model_index_) ? 424 return model_->IsHoveredIndex(model_index_) ? HOVERED : NORMAL;
401 kHoverBackgroundColor : kBackgroundColor;
402 }
403
404 SkColor AutocompleteResultView::GetTextColor() const {
405 return model_->IsSelectedIndex(model_index_) ? kSelectedTextColor
406 : kTextColor;
407 } 425 }
408 426
409 SkBitmap* AutocompleteResultView::GetIcon() const { 427 SkBitmap* AutocompleteResultView::GetIcon() const {
410 bool selected = model_->IsSelectedIndex(model_index_); 428 bool selected = model_->IsSelectedIndex(model_index_);
411 if (match_.starred) 429 if (match_.starred)
412 return selected ? icon_star_selected_ : icon_star_; 430 return selected ? icon_star_selected_ : icon_star_;
413 switch (match_.type) { 431 switch (match_.type) {
414 case AutocompleteMatch::URL_WHAT_YOU_TYPED: 432 case AutocompleteMatch::URL_WHAT_YOU_TYPED:
415 case AutocompleteMatch::HISTORY_URL: 433 case AutocompleteMatch::HISTORY_URL:
416 case AutocompleteMatch::NAVSUGGEST: 434 case AutocompleteMatch::NAVSUGGEST:
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 string_width, display_font.height()); 540 string_width, display_font.height());
523 return string_width; 541 return string_width;
524 } 542 }
525 543
526 gfx::Font AutocompleteResultView::GetFragmentFont(int style) const { 544 gfx::Font AutocompleteResultView::GetFragmentFont(int style) const {
527 return (style & ACMatchClassification::MATCH) ? 545 return (style & ACMatchClassification::MATCH) ?
528 font_.DeriveFont(0, gfx::Font::BOLD) : font_; 546 font_.DeriveFont(0, gfx::Font::BOLD) : font_;
529 } 547 }
530 548
531 SkColor AutocompleteResultView::GetFragmentTextColor(int style) const { 549 SkColor AutocompleteResultView::GetFragmentTextColor(int style) const {
532 bool selected = model_->IsSelectedIndex(model_index_); 550 const ResultViewState state = GetState();
533 if (style & ACMatchClassification::URL) { 551 if (style & ACMatchClassification::URL)
534 // TODO(beng): bring over the contrast logic from the old popup and massage 552 return GetColor(state, URL);
535 // these values. See autocomplete_popup_view_win.cc and 553 return GetColor(state,
536 // LuminosityContrast etc. 554 (style & ACMatchClassification::DIM) ? DIMMED_TEXT : TEXT);
537 return selected ? kHighlightURLColor : kStandardURLColor;
538 }
539 if (style & ACMatchClassification::DIM)
540 return selected ? kSelectedDimTextColor : kDimTextColor;
541 return GetTextColor();
542 } 555 }
543 556
544 void AutocompleteResultView::InitClass() { 557 void AutocompleteResultView::InitClass() {
545 if (!initialized_) { 558 if (!initialized_) {
546 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 559 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
547 icon_url_ = rb.GetBitmapNamed(IDR_O2_GLOBE); 560 icon_url_ = rb.GetBitmapNamed(IDR_O2_GLOBE);
548 icon_url_selected_ = rb.GetBitmapNamed(IDR_O2_GLOBE_SELECTED); 561 icon_url_selected_ = rb.GetBitmapNamed(IDR_O2_GLOBE_SELECTED);
549 icon_history_ = rb.GetBitmapNamed(IDR_O2_HISTORY); 562 icon_history_ = rb.GetBitmapNamed(IDR_O2_HISTORY);
550 icon_history_selected_ = rb.GetBitmapNamed(IDR_O2_HISTORY_SELECTED); 563 icon_history_selected_ = rb.GetBitmapNamed(IDR_O2_HISTORY_SELECTED);
551 icon_search_ = rb.GetBitmapNamed(IDR_O2_SEARCH); 564 icon_search_ = rb.GetBitmapNamed(IDR_O2_SEARCH);
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 // 844 //
832 // Because the border of this view creates an anti-aliased round-rect region 845 // Because the border of this view creates an anti-aliased round-rect region
833 // for the contents, we need to render our rectangular result child views into 846 // for the contents, we need to render our rectangular result child views into
834 // this round rect region. We can't use a simple clip because clipping is 847 // this round rect region. We can't use a simple clip because clipping is
835 // 1-bit and we get nasty jagged edges. 848 // 1-bit and we get nasty jagged edges.
836 // 849 //
837 // Instead, we paint all our children into a second canvas and use that as a 850 // Instead, we paint all our children into a second canvas and use that as a
838 // shader to fill a path representing the round-rect clipping region. This 851 // shader to fill a path representing the round-rect clipping region. This
839 // yields a nice anti-aliased edge. 852 // yields a nice anti-aliased edge.
840 gfx::Canvas contents_canvas(width(), height(), true); 853 gfx::Canvas contents_canvas(width(), height(), true);
841 contents_canvas.FillRectInt(kBackgroundColor, 0, 0, width(), height()); 854 contents_canvas.drawColor(GetColor(NORMAL, BACKGROUND));
842 View::PaintChildren(&contents_canvas); 855 View::PaintChildren(&contents_canvas);
843 // We want the contents background to be slightly transparent so we can see 856 // We want the contents background to be slightly transparent so we can see
844 // the blurry glass effect on DWM systems behind. We do this _after_ we paint 857 // the blurry glass effect on DWM systems behind. We do this _after_ we paint
845 // the children since they paint text, and GDI will reset this alpha data if 858 // the children since they paint text, and GDI will reset this alpha data if
846 // we paint text after this call. 859 // we paint text after this call.
847 MakeCanvasTransparent(&contents_canvas); 860 MakeCanvasTransparent(&contents_canvas);
848 861
849 // Now paint the contents of the contents canvas into the actual canvas. 862 // Now paint the contents of the contents canvas into the actual canvas.
850 SkPaint paint; 863 SkPaint paint;
851 paint.setAntiAlias(true); 864 paint.setAntiAlias(true);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 ScopedGDIObject<HRGN> popup_region; 943 ScopedGDIObject<HRGN> popup_region;
931 popup_region.Set(contents_path.CreateHRGN()); 944 popup_region.Set(contents_path.CreateHRGN());
932 bb.hRgnBlur = popup_region.Get(); 945 bb.hRgnBlur = popup_region.Get();
933 DwmEnableBlurBehindWindow(GetWidget()->GetNativeView(), &bb); 946 DwmEnableBlurBehindWindow(GetWidget()->GetNativeView(), &bb);
934 #endif 947 #endif
935 } 948 }
936 949
937 void AutocompletePopupContentsView::MakeCanvasTransparent( 950 void AutocompletePopupContentsView::MakeCanvasTransparent(
938 gfx::Canvas* canvas) { 951 gfx::Canvas* canvas) {
939 // Allow the window blur effect to show through the popup background. 952 // Allow the window blur effect to show through the popup background.
940 SkPaint paint; 953 SkAlpha alpha = GetThemeProvider()->ShouldUseNativeFrame() ?
941 SkColor transparency = GetThemeProvider()->ShouldUseNativeFrame() ? 954 kGlassPopupAlpha : kOpaquePopupAlpha;
942 kGlassPopupTransparency : kOpaquePopupTransparency; 955 canvas->drawColor(SkColorSetA(GetColor(NORMAL, BACKGROUND), alpha),
943 paint.setColor(SkColorSetARGB(transparency, 255, 255, 255)); 956 SkXfermode::kDstIn_Mode);
944 paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
945 paint.setStyle(SkPaint::kFill_Style);
946 canvas->FillRectInt(0, 0, canvas->getDevice()->width(),
947 canvas->getDevice()->height(), paint);
948 } 957 }
949 958
950 // static 959 // static
951 AutocompletePopupView* AutocompletePopupView::CreatePopupView( 960 AutocompletePopupView* AutocompletePopupView::CreatePopupView(
952 const gfx::Font& font, 961 const gfx::Font& font,
953 AutocompleteEditView* edit_view, 962 AutocompleteEditView* edit_view,
954 AutocompleteEditModel* edit_model, 963 AutocompleteEditModel* edit_model,
955 Profile* profile, 964 Profile* profile,
956 AutocompletePopupPositioner* popup_positioner) { 965 AutocompletePopupPositioner* popup_positioner) {
957 return new AutocompletePopupContentsView(font, edit_view, edit_model, 966 return new AutocompletePopupContentsView(font, edit_view, edit_model,
958 profile, popup_positioner); 967 profile, popup_positioner);
959 } 968 }
OLDNEW
« no previous file with comments | « chrome/browser/toolbar_model.cc ('k') | chrome/browser/views/info_bubble.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698