| 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 |
| 11 #include "app/gfx/chrome_canvas.h" | 11 #include "app/gfx/canvas.h" |
| 12 #include "app/gfx/color_utils.h" | 12 #include "app/gfx/color_utils.h" |
| 13 #include "app/gfx/insets.h" | 13 #include "app/gfx/insets.h" |
| 14 #include "app/gfx/path.h" | 14 #include "app/gfx/path.h" |
| 15 #include "app/l10n_util.h" | 15 #include "app/l10n_util.h" |
| 16 #include "app/resource_bundle.h" | 16 #include "app/resource_bundle.h" |
| 17 #include "app/win_util.h" | 17 #include "app/win_util.h" |
| 18 #include "chrome/browser/autocomplete/autocomplete_edit_view_win.h" | 18 #include "chrome/browser/autocomplete/autocomplete_edit_view_win.h" |
| 19 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 19 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 20 #include "chrome/browser/views/autocomplete/autocomplete_popup_win.h" | 20 #include "chrome/browser/views/autocomplete/autocomplete_popup_win.h" |
| 21 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 gfx::Font& 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(gfx::Canvas* 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); |
| 81 virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled); | 81 virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled); |
| 82 virtual bool OnMouseDragged(const views::MouseEvent& event); | 82 virtual bool OnMouseDragged(const views::MouseEvent& event); |
| 83 | 83 |
| 84 private: | 84 private: |
| 85 // Get colors for row backgrounds and text for different row states. | 85 // Get colors for row backgrounds and text for different row states. |
| 86 SkColor GetBackgroundColor() const; | 86 SkColor GetBackgroundColor() const; |
| 87 SkColor GetTextColor() const; | 87 SkColor GetTextColor() const; |
| 88 | 88 |
| 89 SkBitmap* GetIcon() const; | 89 SkBitmap* GetIcon() const; |
| 90 | 90 |
| 91 // Draws the specified |text| into the canvas, using highlighting provided by | 91 // Draws the specified |text| into the canvas, using highlighting provided by |
| 92 // |classifications|. If |force_dim| is true, ACMatchClassification::DIM is | 92 // |classifications|. If |force_dim| is true, ACMatchClassification::DIM is |
| 93 // added to all of the classifications. Returns the x position to the right | 93 // added to all of the classifications. Returns the x position to the right |
| 94 // of the string. | 94 // of the string. |
| 95 int DrawString(ChromeCanvas* canvas, | 95 int DrawString(gfx::Canvas* canvas, |
| 96 const std::wstring& text, | 96 const std::wstring& text, |
| 97 const ACMatchClassifications& classifications, | 97 const ACMatchClassifications& classifications, |
| 98 bool force_dim, | 98 bool force_dim, |
| 99 int x, | 99 int x, |
| 100 int y); | 100 int y); |
| 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(gfx::Canvas* 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 gfx::Font 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. |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 } |
| 286 | 286 |
| 287 void AutocompleteResultView::Paint(ChromeCanvas* canvas) { | 287 void AutocompleteResultView::Paint(gfx::Canvas* canvas) { |
| 288 canvas->FillRectInt(GetBackgroundColor(), 0, 0, width(), height()); | 288 canvas->FillRectInt(GetBackgroundColor(), 0, 0, width(), height()); |
| 289 | 289 |
| 290 int x = MirroredLeftPointForRect(icon_bounds_); | 290 int x = MirroredLeftPointForRect(icon_bounds_); |
| 291 | 291 |
| 292 // Paint the icon. | 292 // Paint the icon. |
| 293 canvas->DrawBitmapInt(*GetIcon(), x, icon_bounds_.y()); | 293 canvas->DrawBitmapInt(*GetIcon(), x, icon_bounds_.y()); |
| 294 | 294 |
| 295 const AutocompleteMatch& match = model_->GetMatchAtIndex(model_index_); | 295 const AutocompleteMatch& match = model_->GetMatchAtIndex(model_index_); |
| 296 | 296 |
| 297 // Paint the text. | 297 // Paint the text. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 case AutocompleteMatch::OPEN_HISTORY_PAGE: | 414 case AutocompleteMatch::OPEN_HISTORY_PAGE: |
| 415 return selected ? icon_more_selected_ : icon_more_; | 415 return selected ? icon_more_selected_ : icon_more_; |
| 416 default: | 416 default: |
| 417 NOTREACHED(); | 417 NOTREACHED(); |
| 418 break; | 418 break; |
| 419 } | 419 } |
| 420 return NULL; | 420 return NULL; |
| 421 } | 421 } |
| 422 | 422 |
| 423 int AutocompleteResultView::DrawString( | 423 int AutocompleteResultView::DrawString( |
| 424 ChromeCanvas* canvas, | 424 gfx::Canvas* canvas, |
| 425 const std::wstring& text, | 425 const std::wstring& text, |
| 426 const ACMatchClassifications& classifications, | 426 const ACMatchClassifications& classifications, |
| 427 bool force_dim, | 427 bool force_dim, |
| 428 int x, | 428 int x, |
| 429 int y) { | 429 int y) { |
| 430 if (!text.length()) | 430 if (!text.length()) |
| 431 return x; | 431 return x; |
| 432 | 432 |
| 433 // Initialize a bidirectional line iterator of ICU and split the text into | 433 // Initialize a bidirectional line iterator of ICU and split the text into |
| 434 // visual runs. (A visual run is consecutive characters which have the same | 434 // visual runs. (A visual run is consecutive characters which have the same |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 x += DrawStringFragment(canvas, | 487 x += DrawStringFragment(canvas, |
| 488 text.substr(text_start, text_end - text_start), | 488 text.substr(text_start, text_end - text_start), |
| 489 style, x, y); | 489 style, x, y); |
| 490 } | 490 } |
| 491 } | 491 } |
| 492 } | 492 } |
| 493 return x; | 493 return x; |
| 494 } | 494 } |
| 495 | 495 |
| 496 int AutocompleteResultView::DrawStringFragment( | 496 int AutocompleteResultView::DrawStringFragment( |
| 497 ChromeCanvas* canvas, | 497 gfx::Canvas* 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 gfx::Font 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); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 } | 556 } |
| 557 virtual ~PopupBorder() {} | 557 virtual ~PopupBorder() {} |
| 558 | 558 |
| 559 // Returns the border radius of the edge of the popup. | 559 // Returns the border radius of the edge of the popup. |
| 560 static int GetBorderRadius() { | 560 static int GetBorderRadius() { |
| 561 InitClass(); | 561 InitClass(); |
| 562 return dropshadow_topleft_->width() - dropshadow_left_->width() - 1; | 562 return dropshadow_topleft_->width() - dropshadow_left_->width() - 1; |
| 563 } | 563 } |
| 564 | 564 |
| 565 // Overridden from views::Border: | 565 // Overridden from views::Border: |
| 566 virtual void Paint(const views::View& view, ChromeCanvas* canvas) const; | 566 virtual void Paint(const views::View& view, gfx::Canvas* canvas) const; |
| 567 virtual void GetInsets(gfx::Insets* insets) const; | 567 virtual void GetInsets(gfx::Insets* insets) const; |
| 568 | 568 |
| 569 private: | 569 private: |
| 570 // Border graphics. | 570 // Border graphics. |
| 571 static SkBitmap* dropshadow_left_; | 571 static SkBitmap* dropshadow_left_; |
| 572 static SkBitmap* dropshadow_topleft_; | 572 static SkBitmap* dropshadow_topleft_; |
| 573 static SkBitmap* dropshadow_top_; | 573 static SkBitmap* dropshadow_top_; |
| 574 static SkBitmap* dropshadow_topright_; | 574 static SkBitmap* dropshadow_topright_; |
| 575 static SkBitmap* dropshadow_right_; | 575 static SkBitmap* dropshadow_right_; |
| 576 static SkBitmap* dropshadow_bottomright_; | 576 static SkBitmap* dropshadow_bottomright_; |
| 577 static SkBitmap* dropshadow_bottom_; | 577 static SkBitmap* dropshadow_bottom_; |
| 578 static SkBitmap* dropshadow_bottomleft_; | 578 static SkBitmap* dropshadow_bottomleft_; |
| 579 | 579 |
| 580 static void InitClass(); | 580 static void InitClass(); |
| 581 | 581 |
| 582 DISALLOW_COPY_AND_ASSIGN(PopupBorder); | 582 DISALLOW_COPY_AND_ASSIGN(PopupBorder); |
| 583 }; | 583 }; |
| 584 | 584 |
| 585 // static | 585 // static |
| 586 SkBitmap* PopupBorder::dropshadow_left_ = NULL; | 586 SkBitmap* PopupBorder::dropshadow_left_ = NULL; |
| 587 SkBitmap* PopupBorder::dropshadow_topleft_ = NULL; | 587 SkBitmap* PopupBorder::dropshadow_topleft_ = NULL; |
| 588 SkBitmap* PopupBorder::dropshadow_top_ = NULL; | 588 SkBitmap* PopupBorder::dropshadow_top_ = NULL; |
| 589 SkBitmap* PopupBorder::dropshadow_topright_ = NULL; | 589 SkBitmap* PopupBorder::dropshadow_topright_ = NULL; |
| 590 SkBitmap* PopupBorder::dropshadow_right_ = NULL; | 590 SkBitmap* PopupBorder::dropshadow_right_ = NULL; |
| 591 SkBitmap* PopupBorder::dropshadow_bottomright_ = NULL; | 591 SkBitmap* PopupBorder::dropshadow_bottomright_ = NULL; |
| 592 SkBitmap* PopupBorder::dropshadow_bottom_ = NULL; | 592 SkBitmap* PopupBorder::dropshadow_bottom_ = NULL; |
| 593 SkBitmap* PopupBorder::dropshadow_bottomleft_ = NULL; | 593 SkBitmap* PopupBorder::dropshadow_bottomleft_ = NULL; |
| 594 | 594 |
| 595 void PopupBorder::Paint(const views::View& view, ChromeCanvas* canvas) const { | 595 void PopupBorder::Paint(const views::View& view, gfx::Canvas* canvas) const { |
| 596 int ds_tl_width = dropshadow_topleft_->width(); | 596 int ds_tl_width = dropshadow_topleft_->width(); |
| 597 int ds_tl_height = dropshadow_topleft_->height(); | 597 int ds_tl_height = dropshadow_topleft_->height(); |
| 598 int ds_tr_width = dropshadow_topright_->width(); | 598 int ds_tr_width = dropshadow_topright_->width(); |
| 599 int ds_tr_height = dropshadow_topright_->height(); | 599 int ds_tr_height = dropshadow_topright_->height(); |
| 600 int ds_br_width = dropshadow_bottomright_->width(); | 600 int ds_br_width = dropshadow_bottomright_->width(); |
| 601 int ds_br_height = dropshadow_bottomright_->height(); | 601 int ds_br_height = dropshadow_bottomright_->height(); |
| 602 int ds_bl_width = dropshadow_bottomleft_->width(); | 602 int ds_bl_width = dropshadow_bottomleft_->width(); |
| 603 int ds_bl_height = dropshadow_bottomleft_->height(); | 603 int ds_bl_height = dropshadow_bottomleft_->height(); |
| 604 | 604 |
| 605 canvas->DrawBitmapInt(*dropshadow_topleft_, 0, 0); | 605 canvas->DrawBitmapInt(*dropshadow_topleft_, 0, 0); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 } | 760 } |
| 761 | 761 |
| 762 void AutocompletePopupContentsView::SetSelectedLine(size_t index, | 762 void AutocompletePopupContentsView::SetSelectedLine(size_t index, |
| 763 bool revert_to_default) { | 763 bool revert_to_default) { |
| 764 model_->SetSelectedLine(index, revert_to_default); | 764 model_->SetSelectedLine(index, revert_to_default); |
| 765 } | 765 } |
| 766 | 766 |
| 767 //////////////////////////////////////////////////////////////////////////////// | 767 //////////////////////////////////////////////////////////////////////////////// |
| 768 // AutocompletePopupContentsView, views::View overrides: | 768 // AutocompletePopupContentsView, views::View overrides: |
| 769 | 769 |
| 770 void AutocompletePopupContentsView::PaintChildren(ChromeCanvas* canvas) { | 770 void AutocompletePopupContentsView::PaintChildren(gfx::Canvas* canvas) { |
| 771 // We paint our children in an unconventional way. | 771 // We paint our children in an unconventional way. |
| 772 // | 772 // |
| 773 // Because the border of this view creates an anti-aliased round-rect region | 773 // Because the border of this view creates an anti-aliased round-rect region |
| 774 // for the contents, we need to render our rectangular result child views into | 774 // for the contents, we need to render our rectangular result child views into |
| 775 // this round rect region. We can't use a simple clip because clipping is | 775 // this round rect region. We can't use a simple clip because clipping is |
| 776 // 1-bit and we get nasty jagged edges. | 776 // 1-bit and we get nasty jagged edges. |
| 777 // | 777 // |
| 778 // Instead, we paint all our children into a second canvas and use that as a | 778 // Instead, we paint all our children into a second canvas and use that as a |
| 779 // shader to fill a path representing the round-rect clipping region. This | 779 // shader to fill a path representing the round-rect clipping region. This |
| 780 // yields a nice anti-aliased edge. | 780 // yields a nice anti-aliased edge. |
| 781 ChromeCanvas contents_canvas(width(), height(), true); | 781 gfx::Canvas contents_canvas(width(), height(), true); |
| 782 contents_canvas.FillRectInt(kBackgroundColor, 0, 0, width(), height()); | 782 contents_canvas.FillRectInt(kBackgroundColor, 0, 0, width(), height()); |
| 783 View::PaintChildren(&contents_canvas); | 783 View::PaintChildren(&contents_canvas); |
| 784 // We want the contents background to be slightly transparent so we can see | 784 // We want the contents background to be slightly transparent so we can see |
| 785 // the blurry glass effect on DWM systems behind. We do this _after_ we paint | 785 // the blurry glass effect on DWM systems behind. We do this _after_ we paint |
| 786 // the children since they paint text, and GDI will reset this alpha data if | 786 // the children since they paint text, and GDI will reset this alpha data if |
| 787 // we paint text after this call. | 787 // we paint text after this call. |
| 788 MakeCanvasTransparent(&contents_canvas); | 788 MakeCanvasTransparent(&contents_canvas); |
| 789 | 789 |
| 790 // Now paint the contents of the contents canvas into the actual canvas. | 790 // Now paint the contents of the contents canvas into the actual canvas. |
| 791 SkPaint paint; | 791 SkPaint paint; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 | 858 |
| 859 gfx::Path contents_path; | 859 gfx::Path contents_path; |
| 860 MakeContentsPath(&contents_path, contents_rect); | 860 MakeContentsPath(&contents_path, contents_rect); |
| 861 ScopedGDIObject<HRGN> popup_region; | 861 ScopedGDIObject<HRGN> popup_region; |
| 862 popup_region.Set(contents_path.CreateHRGN()); | 862 popup_region.Set(contents_path.CreateHRGN()); |
| 863 bb.hRgnBlur = popup_region.Get(); | 863 bb.hRgnBlur = popup_region.Get(); |
| 864 DwmEnableBlurBehindWindow(GetWidget()->GetNativeView(), &bb); | 864 DwmEnableBlurBehindWindow(GetWidget()->GetNativeView(), &bb); |
| 865 } | 865 } |
| 866 | 866 |
| 867 void AutocompletePopupContentsView::MakeCanvasTransparent( | 867 void AutocompletePopupContentsView::MakeCanvasTransparent( |
| 868 ChromeCanvas* canvas) { | 868 gfx::Canvas* canvas) { |
| 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 |