| OLD | NEW |
| 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 <objidl.h> | 7 #include <objidl.h> |
| 8 #include <commctrl.h> | 8 #include <commctrl.h> |
| 9 #include <dwmapi.h> | 9 #include <dwmapi.h> |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 // kIconVerticalPadding. | 53 // kIconVerticalPadding. |
| 54 static const int kTextVerticalPadding = 3; | 54 static const int kTextVerticalPadding = 3; |
| 55 // The padding at the left edge of the row, left of the icon. | 55 // The padding at the left edge of the row, left of the icon. |
| 56 static const int kRowLeftPadding = 6; | 56 static const int kRowLeftPadding = 6; |
| 57 // The padding on the right edge of the row, right of the text. | 57 // The padding on the right edge of the row, right of the text. |
| 58 static const int kRowRightPadding = 3; | 58 static const int kRowRightPadding = 3; |
| 59 // The horizontal distance between the right edge of the icon and the left edge | 59 // The horizontal distance between the right edge of the icon and the left edge |
| 60 // of the text. | 60 // of the text. |
| 61 static const int kIconTextSpacing = 9; | 61 static const int kIconTextSpacing = 9; |
| 62 // The size delta between the font used for the edit and the result rows. Passed | 62 // The size delta between the font used for the edit and the result rows. Passed |
| 63 // to ChromeFont::DeriveFont. | 63 // to gfx::Font::DeriveFont. |
| 64 static const int kEditFontAdjust = -1; | 64 static const int kEditFontAdjust = -1; |
| 65 | 65 |
| 66 class AutocompleteResultView : public views::View { | 66 class AutocompleteResultView : public views::View { |
| 67 public: | 67 public: |
| 68 AutocompleteResultView(AutocompleteResultViewModel* model, | 68 AutocompleteResultView(AutocompleteResultViewModel* model, |
| 69 int model_index, | 69 int model_index, |
| 70 const ChromeFont& font); | 70 const gfx::Font& font); |
| 71 virtual ~AutocompleteResultView(); | 71 virtual ~AutocompleteResultView(); |
| 72 | 72 |
| 73 // Overridden from views::View: | 73 // Overridden from views::View: |
| 74 virtual void Paint(ChromeCanvas* canvas); | 74 virtual void Paint(ChromeCanvas* canvas); |
| 75 virtual void Layout(); | 75 virtual void Layout(); |
| 76 virtual gfx::Size GetPreferredSize(); | 76 virtual gfx::Size GetPreferredSize(); |
| 77 virtual void OnMouseEntered(const views::MouseEvent& event); | 77 virtual void OnMouseEntered(const views::MouseEvent& event); |
| 78 virtual void OnMouseMoved(const views::MouseEvent& event); | 78 virtual void OnMouseMoved(const views::MouseEvent& event); |
| 79 virtual void OnMouseExited(const views::MouseEvent& event); | 79 virtual void OnMouseExited(const views::MouseEvent& event); |
| 80 virtual bool OnMousePressed(const views::MouseEvent& event); | 80 virtual bool OnMousePressed(const views::MouseEvent& event); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 101 | 101 |
| 102 // Draws an individual sub-fragment with the specified style. Returns the x | 102 // Draws an individual sub-fragment with the specified style. Returns the x |
| 103 // position to the right of the fragment. | 103 // position to the right of the fragment. |
| 104 int DrawStringFragment(ChromeCanvas* canvas, | 104 int DrawStringFragment(ChromeCanvas* canvas, |
| 105 const std::wstring& text, | 105 const std::wstring& text, |
| 106 int style, | 106 int style, |
| 107 int x, | 107 int x, |
| 108 int y); | 108 int y); |
| 109 | 109 |
| 110 // Gets the font and text color for a fragment with the specified style. | 110 // Gets the font and text color for a fragment with the specified style. |
| 111 ChromeFont GetFragmentFont(int style) const; | 111 gfx::Font GetFragmentFont(int style) const; |
| 112 SkColor GetFragmentTextColor(int style) const; | 112 SkColor GetFragmentTextColor(int style) const; |
| 113 | 113 |
| 114 // This row's model and model index. | 114 // This row's model and model index. |
| 115 AutocompleteResultViewModel* model_; | 115 AutocompleteResultViewModel* model_; |
| 116 size_t model_index_; | 116 size_t model_index_; |
| 117 | 117 |
| 118 // True if the mouse is over this row. | 118 // True if the mouse is over this row. |
| 119 bool hot_; | 119 bool hot_; |
| 120 | 120 |
| 121 // The font used to derive fonts for rendering the text in this row. | 121 // The font used to derive fonts for rendering the text in this row. |
| 122 ChromeFont font_; | 122 gfx::Font font_; |
| 123 | 123 |
| 124 // A context used for mirroring regions. | 124 // A context used for mirroring regions. |
| 125 class MirroringContext; | 125 class MirroringContext; |
| 126 scoped_ptr<MirroringContext> mirroring_context_; | 126 scoped_ptr<MirroringContext> mirroring_context_; |
| 127 | 127 |
| 128 // Layout rects for various sub-components of the view. | 128 // Layout rects for various sub-components of the view. |
| 129 gfx::Rect icon_bounds_; | 129 gfx::Rect icon_bounds_; |
| 130 gfx::Rect text_bounds_; | 130 gfx::Rect text_bounds_; |
| 131 | 131 |
| 132 // Icons for rows. | 132 // Icons for rows. |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 } | 265 } |
| 266 | 266 |
| 267 int AutocompleteResultView::MirroringContext::GetLeft(int x1, int x2) const { | 267 int AutocompleteResultView::MirroringContext::GetLeft(int x1, int x2) const { |
| 268 return mirrored_ ? | 268 return mirrored_ ? |
| 269 (center_x_ + (center_x_ - std::max(x1, x2))) : std::min(x1, x2); | 269 (center_x_ + (center_x_ - std::max(x1, x2))) : std::min(x1, x2); |
| 270 } | 270 } |
| 271 | 271 |
| 272 AutocompleteResultView::AutocompleteResultView( | 272 AutocompleteResultView::AutocompleteResultView( |
| 273 AutocompleteResultViewModel* model, | 273 AutocompleteResultViewModel* model, |
| 274 int model_index, | 274 int model_index, |
| 275 const ChromeFont& font) | 275 const gfx::Font& font) |
| 276 : model_(model), | 276 : model_(model), |
| 277 model_index_(model_index), | 277 model_index_(model_index), |
| 278 hot_(false), | 278 hot_(false), |
| 279 font_(font), | 279 font_(font), |
| 280 mirroring_context_(new MirroringContext()) { | 280 mirroring_context_(new MirroringContext()) { |
| 281 InitClass(); | 281 InitClass(); |
| 282 } | 282 } |
| 283 | 283 |
| 284 AutocompleteResultView::~AutocompleteResultView() { | 284 AutocompleteResultView::~AutocompleteResultView() { |
| 285 } | 285 } |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 } | 492 } |
| 493 return x; | 493 return x; |
| 494 } | 494 } |
| 495 | 495 |
| 496 int AutocompleteResultView::DrawStringFragment( | 496 int AutocompleteResultView::DrawStringFragment( |
| 497 ChromeCanvas* canvas, | 497 ChromeCanvas* canvas, |
| 498 const std::wstring& text, | 498 const std::wstring& text, |
| 499 int style, | 499 int style, |
| 500 int x, | 500 int x, |
| 501 int y) { | 501 int y) { |
| 502 ChromeFont display_font = GetFragmentFont(style); | 502 gfx::Font display_font = GetFragmentFont(style); |
| 503 // Clamp text width to the available width within the popup so we elide if | 503 // Clamp text width to the available width within the popup so we elide if |
| 504 // necessary. | 504 // necessary. |
| 505 int string_width = std::min(display_font.GetStringWidth(text), | 505 int string_width = std::min(display_font.GetStringWidth(text), |
| 506 width() - kRowRightPadding - x); | 506 width() - kRowRightPadding - x); |
| 507 int string_left = mirroring_context_->GetLeft(x, x + string_width); | 507 int string_left = mirroring_context_->GetLeft(x, x + string_width); |
| 508 canvas->DrawStringInt(text, GetFragmentFont(style), | 508 canvas->DrawStringInt(text, GetFragmentFont(style), |
| 509 GetFragmentTextColor(style), string_left, y, | 509 GetFragmentTextColor(style), string_left, y, |
| 510 string_width, display_font.height()); | 510 string_width, display_font.height()); |
| 511 return string_width; | 511 return string_width; |
| 512 } | 512 } |
| 513 | 513 |
| 514 ChromeFont AutocompleteResultView::GetFragmentFont(int style) const { | 514 gfx::Font AutocompleteResultView::GetFragmentFont(int style) const { |
| 515 if (style & ACMatchClassification::MATCH) | 515 if (style & ACMatchClassification::MATCH) |
| 516 return font_.DeriveFont(0, ChromeFont::BOLD); | 516 return font_.DeriveFont(0, gfx::Font::BOLD); |
| 517 return font_; | 517 return font_; |
| 518 } | 518 } |
| 519 | 519 |
| 520 SkColor AutocompleteResultView::GetFragmentTextColor(int style) const { | 520 SkColor AutocompleteResultView::GetFragmentTextColor(int style) const { |
| 521 bool selected = model_->IsSelectedIndex(model_index_); | 521 bool selected = model_->IsSelectedIndex(model_index_); |
| 522 if (style & ACMatchClassification::URL) { | 522 if (style & ACMatchClassification::URL) { |
| 523 // TODO(beng): bring over the contrast logic from the old popup and massage | 523 // TODO(beng): bring over the contrast logic from the old popup and massage |
| 524 // these values. See autocomplete_popup_view_win.cc and | 524 // these values. See autocomplete_popup_view_win.cc and |
| 525 // LuminosityContrast etc. | 525 // LuminosityContrast etc. |
| 526 return selected ? kHighlightURLColor : kStandardURLColor; | 526 return selected ? kHighlightURLColor : kStandardURLColor; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 dropshadow_bottom_ = rb.GetBitmapNamed(IDR_OMNIBOX_POPUP_DS_B); | 644 dropshadow_bottom_ = rb.GetBitmapNamed(IDR_OMNIBOX_POPUP_DS_B); |
| 645 dropshadow_bottomleft_ = rb.GetBitmapNamed(IDR_OMNIBOX_POPUP_DS_BL); | 645 dropshadow_bottomleft_ = rb.GetBitmapNamed(IDR_OMNIBOX_POPUP_DS_BL); |
| 646 initialized = true; | 646 initialized = true; |
| 647 } | 647 } |
| 648 } | 648 } |
| 649 | 649 |
| 650 //////////////////////////////////////////////////////////////////////////////// | 650 //////////////////////////////////////////////////////////////////////////////// |
| 651 // AutocompletePopupContentsView, public: | 651 // AutocompletePopupContentsView, public: |
| 652 | 652 |
| 653 AutocompletePopupContentsView::AutocompletePopupContentsView( | 653 AutocompletePopupContentsView::AutocompletePopupContentsView( |
| 654 const ChromeFont& font, | 654 const gfx::Font& font, |
| 655 AutocompleteEditViewWin* edit_view, | 655 AutocompleteEditViewWin* edit_view, |
| 656 AutocompleteEditModel* edit_model, | 656 AutocompleteEditModel* edit_model, |
| 657 Profile* profile, | 657 Profile* profile, |
| 658 AutocompletePopupPositioner* popup_positioner) | 658 AutocompletePopupPositioner* popup_positioner) |
| 659 : popup_(new AutocompletePopupWin(this)), | 659 : popup_(new AutocompletePopupWin(this)), |
| 660 model_(new AutocompletePopupModel(this, edit_model, profile)), | 660 model_(new AutocompletePopupModel(this, edit_model, profile)), |
| 661 edit_view_(edit_view), | 661 edit_view_(edit_view), |
| 662 popup_positioner_(popup_positioner), | 662 popup_positioner_(popup_positioner), |
| 663 result_font_(font.DeriveFont(kEditFontAdjust)) { | 663 result_font_(font.DeriveFont(kEditFontAdjust)) { |
| 664 set_border(new PopupBorder); | 664 set_border(new PopupBorder); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 // Allow the window blur effect to show through the popup background. | 869 // Allow the window blur effect to show through the popup background. |
| 870 SkPaint paint; | 870 SkPaint paint; |
| 871 SkColor transparency = win_util::ShouldUseVistaFrame() ? | 871 SkColor transparency = win_util::ShouldUseVistaFrame() ? |
| 872 kGlassPopupTransparency : kOpaquePopupTransparency; | 872 kGlassPopupTransparency : kOpaquePopupTransparency; |
| 873 paint.setColor(SkColorSetARGB(transparency, 255, 255, 255)); | 873 paint.setColor(SkColorSetARGB(transparency, 255, 255, 255)); |
| 874 paint.setPorterDuffXfermode(SkPorterDuff::kDstIn_Mode); | 874 paint.setPorterDuffXfermode(SkPorterDuff::kDstIn_Mode); |
| 875 paint.setStyle(SkPaint::kFill_Style); | 875 paint.setStyle(SkPaint::kFill_Style); |
| 876 canvas->FillRectInt(0, 0, canvas->getDevice()->width(), | 876 canvas->FillRectInt(0, 0, canvas->getDevice()->width(), |
| 877 canvas->getDevice()->height(), paint); | 877 canvas->getDevice()->height(), paint); |
| 878 } | 878 } |
| OLD | NEW |