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

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: use Background instead of a separate Part 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
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "ui/accessibility/ax_view_state.h" 14 #include "ui/accessibility/ax_view_state.h"
15 #include "ui/base/default_style.h" 15 #include "ui/base/default_style.h"
16 #include "ui/base/ime/input_method.h" 16 #include "ui/base/ime/input_method.h"
17 #include "ui/base/models/combobox_model.h" 17 #include "ui/base/models/combobox_model.h"
18 #include "ui/base/models/combobox_model_observer.h" 18 #include "ui/base/models/combobox_model_observer.h"
19 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/events/event.h" 20 #include "ui/events/event.h"
21 #include "ui/gfx/animation/throb_animation.h" 21 #include "ui/gfx/animation/throb_animation.h"
22 #include "ui/gfx/canvas.h" 22 #include "ui/gfx/canvas.h"
23 #include "ui/gfx/color_palette.h" 23 #include "ui/gfx/color_palette.h"
24 #include "ui/gfx/scoped_canvas.h" 24 #include "ui/gfx/scoped_canvas.h"
25 #include "ui/gfx/text_utils.h" 25 #include "ui/gfx/text_utils.h"
26 #include "ui/native_theme/common_theme.h" 26 #include "ui/native_theme/common_theme.h"
27 #include "ui/native_theme/native_theme.h" 27 #include "ui/native_theme/native_theme.h"
28 #include "ui/native_theme/native_theme_aura.h" 28 #include "ui/native_theme/native_theme_aura.h"
29 #include "ui/resources/grit/ui_resources.h" 29 #include "ui/resources/grit/ui_resources.h"
30 #include "ui/views/background.h"
30 #include "ui/views/controls/button/custom_button.h" 31 #include "ui/views/controls/button/custom_button.h"
31 #include "ui/views/controls/button/label_button.h" 32 #include "ui/views/controls/button/label_button.h"
32 #include "ui/views/controls/combobox/combobox_listener.h" 33 #include "ui/views/controls/combobox/combobox_listener.h"
33 #include "ui/views/controls/focusable_border.h" 34 #include "ui/views/controls/focusable_border.h"
34 #include "ui/views/controls/menu/menu_config.h" 35 #include "ui/views/controls/menu/menu_config.h"
35 #include "ui/views/controls/menu/menu_runner.h" 36 #include "ui/views/controls/menu/menu_runner.h"
36 #include "ui/views/controls/prefix_selector.h" 37 #include "ui/views/controls/prefix_selector.h"
37 #include "ui/views/controls/textfield/textfield.h" 38 #include "ui/views/controls/textfield/textfield.h"
38 #include "ui/views/mouse_constants.h" 39 #include "ui/views/mouse_constants.h"
39 #include "ui/views/painter.h" 40 #include "ui/views/painter.h"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 listener_(NULL), 348 listener_(NULL),
348 selected_index_(model_->GetDefaultIndex()), 349 selected_index_(model_->GetDefaultIndex()),
349 invalid_(false), 350 invalid_(false),
350 menu_model_adapter_(new ComboboxMenuModelAdapter(this, model)), 351 menu_model_adapter_(new ComboboxMenuModelAdapter(this, model)),
351 text_button_(new TransparentButton(this)), 352 text_button_(new TransparentButton(this)),
352 arrow_button_(new TransparentButton(this)), 353 arrow_button_(new TransparentButton(this)),
353 weak_ptr_factory_(this) { 354 weak_ptr_factory_(this) {
354 ModelChanged(); 355 ModelChanged();
355 SetFocusable(true); 356 SetFocusable(true);
356 UpdateBorder(); 357 UpdateBorder();
358 // set_background takes ownership but takes a raw pointer.
tapted 2016/03/22 23:04:32 nit: set_background()
Elly Fong-Jones 2016/03/23 18:07:44 Done.
359 scoped_ptr<Background> b = PlatformStyle::CreateComboboxBackground();
360 set_background(b.release());
357 361
358 // Initialize the button images. 362 // Initialize the button images.
359 Button::ButtonState button_states[] = { 363 Button::ButtonState button_states[] = {
360 Button::STATE_DISABLED, 364 Button::STATE_DISABLED,
361 Button::STATE_NORMAL, 365 Button::STATE_NORMAL,
362 Button::STATE_HOVERED, 366 Button::STATE_HOVERED,
363 Button::STATE_PRESSED, 367 Button::STATE_PRESSED,
364 }; 368 };
365 for (int i = 0; i < 2; i++) { 369 for (int i = 0; i < 2; i++) {
366 for (size_t state_index = 0; state_index < arraysize(button_states); 370 for (size_t state_index = 0; state_index < arraysize(button_states);
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 gfx::Insets insets = GetInsets(); 710 gfx::Insets insets = GetInsets();
707 insets += gfx::Insets(0, Textfield::kTextPadding, 0, Textfield::kTextPadding); 711 insets += gfx::Insets(0, Textfield::kTextPadding, 0, Textfield::kTextPadding);
708 712
709 gfx::ScopedCanvas scoped_canvas(canvas); 713 gfx::ScopedCanvas scoped_canvas(canvas);
710 canvas->ClipRect(GetContentsBounds()); 714 canvas->ClipRect(GetContentsBounds());
711 715
712 int x = insets.left(); 716 int x = insets.left();
713 int y = insets.top(); 717 int y = insets.top();
714 int text_height = height() - insets.height(); 718 int text_height = height() - insets.height();
715 SkColor text_color = GetNativeTheme()->GetSystemColor( 719 SkColor text_color = GetNativeTheme()->GetSystemColor(
716 ui::NativeTheme::kColorId_LabelEnabledColor); 720 enabled() ? ui::NativeTheme::kColorId_LabelEnabledColor :
721 ui::NativeTheme::kColorId_LabelDisabledColor);
717 722
718 DCHECK_GE(selected_index_, 0); 723 DCHECK_GE(selected_index_, 0);
719 DCHECK_LT(selected_index_, model()->GetItemCount()); 724 DCHECK_LT(selected_index_, model()->GetItemCount());
720 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) 725 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount())
721 selected_index_ = 0; 726 selected_index_ = 0;
722 base::string16 text = model()->GetItemAt(selected_index_); 727 base::string16 text = model()->GetItemAt(selected_index_);
723 728
724 gfx::Size arrow_size = ArrowSize(); 729 gfx::Size arrow_size = ArrowSize();
725 int disclosure_arrow_offset = width() - arrow_size.width() - 730 int disclosure_arrow_offset = width() - arrow_size.width() -
726 GetDisclosureArrowLeftPadding() - GetDisclosureArrowRightPadding(); 731 GetDisclosureArrowLeftPadding() - GetDisclosureArrowRightPadding();
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 } 932 }
928 return gfx::Size(width, font_list.GetHeight()); 933 return gfx::Size(width, font_list.GetHeight());
929 } 934 }
930 935
931 PrefixSelector* Combobox::GetPrefixSelector() { 936 PrefixSelector* Combobox::GetPrefixSelector() {
932 if (!selector_) 937 if (!selector_)
933 selector_.reset(new PrefixSelector(this)); 938 selector_.reset(new PrefixSelector(this));
934 return selector_.get(); 939 return selector_.get();
935 } 940 }
936 941
942 int Combobox::GetArrowButtonWidth() const {
tapted 2016/03/22 23:04:32 nit: move up so it matches declaration order
Elly Fong-Jones 2016/03/23 18:07:44 Done.
943 return GetDisclosureArrowLeftPadding() +
944 ArrowSize().width() +
945 GetDisclosureArrowRightPadding();
946 }
947
937 } // namespace views 948 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698