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

Side by Side Diff: ui/views/controls/combobox/combobox.cc

Issue 1819443002: MacViews: draw combobox arrow backgrounds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/controls/combobox/combobox.h" 5 #include "ui/views/controls/combobox/combobox.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 if (e.key_code() == ui::VKEY_SPACE && style_ == STYLE_ACTION) 618 if (e.key_code() == ui::VKEY_SPACE && style_ == STYLE_ACTION)
619 OnPerformAction(); 619 OnPerformAction();
620 620
621 return false; 621 return false;
622 } 622 }
623 623
624 void Combobox::OnPaint(gfx::Canvas* canvas) { 624 void Combobox::OnPaint(gfx::Canvas* canvas) {
625 switch (style_) { 625 switch (style_) {
626 case STYLE_NORMAL: { 626 case STYLE_NORMAL: {
627 OnPaintBackground(canvas); 627 OnPaintBackground(canvas);
628 // Painting the arrow background needs to happen before PaintText applies
629 // a clip rect to |canvas| so the background can touch the border.
630 PaintArrowBackground(canvas);
628 PaintText(canvas); 631 PaintText(canvas);
629 OnPaintBorder(canvas); 632 OnPaintBorder(canvas);
630 break; 633 break;
631 } 634 }
632 case STYLE_ACTION: { 635 case STYLE_ACTION: {
633 PaintButtons(canvas); 636 PaintButtons(canvas);
634 PaintText(canvas); 637 PaintText(canvas);
635 break; 638 break;
636 } 639 }
637 } 640 }
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 if (0 < arrow_button_hover_alpha) { 809 if (0 < arrow_button_hover_alpha) {
807 canvas->SaveLayerAlpha(arrow_button_hover_alpha); 810 canvas->SaveLayerAlpha(arrow_button_hover_alpha);
808 const std::vector<const gfx::ImageSkia*>& arrow_button_hovered_images = 811 const std::vector<const gfx::ImageSkia*>& arrow_button_hovered_images =
809 menu_button_images_[focused][Button::STATE_HOVERED]; 812 menu_button_images_[focused][Button::STATE_HOVERED];
810 PaintArrowButton(canvas, arrow_button_hovered_images, 813 PaintArrowButton(canvas, arrow_button_hovered_images,
811 arrow_button_->x(), height()); 814 arrow_button_->x(), height());
812 canvas->Restore(); 815 canvas->Restore();
813 } 816 }
814 } 817 }
815 818
819 void Combobox::PaintArrowBackground(gfx::Canvas* canvas) {
820 gfx::Canvas::ScopedState canvas_state(canvas);
821
822 if (base::i18n::IsRTL()) {
823 canvas->Translate(gfx::Vector2d(width(), 0));
824 canvas->Scale(-1, 1);
825 }
826
827 gfx::Rect bounds = GetLocalBounds();
828 gfx::Size arrow_size = ArrowSize();
829 int disclosure_arrow_offset = width() - arrow_size.width() -
830 GetDisclosureArrowLeftPadding() - GetDisclosureArrowRightPadding();
831 bounds.Inset(disclosure_arrow_offset, 0, 0, 0);
832
833 ui::NativeTheme::State state =
834 HasFocus() ? ui::NativeTheme::kHovered : ui::NativeTheme::kNormal;
835 GetNativeTheme()->Paint(canvas->sk_canvas(),
836 ui::NativeTheme::kComboboxArrowBackground,
837 state,
838 bounds,
839 ui::NativeTheme::ExtraParams());
840 }
841
816 void Combobox::ShowDropDownMenu(ui::MenuSourceType source_type) { 842 void Combobox::ShowDropDownMenu(ui::MenuSourceType source_type) {
817 gfx::Rect lb = GetLocalBounds(); 843 gfx::Rect lb = GetLocalBounds();
818 gfx::Point menu_position(lb.origin()); 844 gfx::Point menu_position(lb.origin());
819 845
820 if (style_ == STYLE_NORMAL) { 846 if (style_ == STYLE_NORMAL) {
821 // Inset the menu's requested position so the border of the menu lines up 847 // Inset the menu's requested position so the border of the menu lines up
822 // with the border of the combobox. 848 // with the border of the combobox.
823 menu_position.set_x(menu_position.x() + kMenuBorderWidthLeft); 849 menu_position.set_x(menu_position.x() + kMenuBorderWidthLeft);
824 menu_position.set_y(menu_position.y() + kMenuBorderWidthTop); 850 menu_position.set_y(menu_position.y() + kMenuBorderWidthTop);
825 } 851 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 return gfx::Size(width, font_list.GetHeight()); 954 return gfx::Size(width, font_list.GetHeight());
929 } 955 }
930 956
931 PrefixSelector* Combobox::GetPrefixSelector() { 957 PrefixSelector* Combobox::GetPrefixSelector() {
932 if (!selector_) 958 if (!selector_)
933 selector_.reset(new PrefixSelector(this)); 959 selector_.reset(new PrefixSelector(this));
934 return selector_.get(); 960 return selector_.get();
935 } 961 }
936 962
937 } // namespace views 963 } // namespace views
OLDNEW
« ui/native_theme/native_theme_mac.mm ('K') | « ui/views/controls/combobox/combobox.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698