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

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

Issue 2319193002: More Harmony combobox/textfield updates: (Closed)
Patch Set: textfields Created 4 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
« no previous file with comments | « ui/views/controls/combobox/combobox.h ('k') | ui/views/controls/focusable_border.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) 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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 size_to_largest_label_(style_ == STYLE_NORMAL), 399 size_to_largest_label_(style_ == STYLE_NORMAL),
400 weak_ptr_factory_(this) { 400 weak_ptr_factory_(this) {
401 ModelChanged(); 401 ModelChanged();
402 #if defined(OS_MACOSX) 402 #if defined(OS_MACOSX)
403 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); 403 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
404 #else 404 #else
405 SetFocusBehavior(FocusBehavior::ALWAYS); 405 SetFocusBehavior(FocusBehavior::ALWAYS);
406 #endif 406 #endif
407 407
408 UpdateBorder(); 408 UpdateBorder();
409 // set_background() takes ownership but takes a raw pointer. 409 if (UseMd()) {
410 std::unique_ptr<Background> b = 410 // set_background() takes ownership but takes a raw pointer.
411 PlatformStyle::CreateComboboxBackground(GetArrowContainerWidth()); 411 std::unique_ptr<Background> b =
412 set_background(b.release()); 412 PlatformStyle::CreateComboboxBackground(GetArrowContainerWidth());
413 set_background(b.release());
414 }
413 415
414 // Initialize the button images. 416 // Initialize the button images.
415 Button::ButtonState button_states[] = { 417 Button::ButtonState button_states[] = {
416 Button::STATE_DISABLED, 418 Button::STATE_DISABLED,
417 Button::STATE_NORMAL, 419 Button::STATE_NORMAL,
418 Button::STATE_HOVERED, 420 Button::STATE_HOVERED,
419 Button::STATE_PRESSED, 421 Button::STATE_PRESSED,
420 }; 422 };
421 for (int i = 0; i < 2; i++) { 423 for (int i = 0; i < 2; i++) {
422 for (size_t state_index = 0; state_index < arraysize(button_states); 424 for (size_t state_index = 0; state_index < arraysize(button_states);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 } 532 }
531 } 533 }
532 534
533 int arrow_button_x = std::max(0, text_button_width); 535 int arrow_button_x = std::max(0, text_button_width);
534 text_button_->SetBounds(0, 0, std::max(0, text_button_width), height()); 536 text_button_->SetBounds(0, 0, std::max(0, text_button_width), height());
535 arrow_button_->SetBounds(arrow_button_x, 0, arrow_button_width, height()); 537 arrow_button_->SetBounds(arrow_button_x, 0, arrow_button_width, height());
536 } 538 }
537 539
538 void Combobox::OnEnabledChanged() { 540 void Combobox::OnEnabledChanged() {
539 View::OnEnabledChanged(); 541 View::OnEnabledChanged();
540 arrow_image_ = PlatformStyle::CreateComboboxArrow(enabled(), style_); 542 if (!UseMd())
543 arrow_image_ = PlatformStyle::CreateComboboxArrow(enabled(), style_);
544 }
545
546 void Combobox::OnNativeThemeChanged(const ui::NativeTheme* theme) {
547 if (!UseMd())
548 return;
549
550 set_background(Background::CreateBackgroundPainter(
551 true, Painter::CreateSolidRoundRectPainter(
552 theme->GetSystemColor(
553 ui::NativeTheme::kColorId_TextfieldDefaultBackground),
554 FocusableBorder::kCornerRadiusDp)));
541 } 555 }
542 556
543 int Combobox::GetRowCount() { 557 int Combobox::GetRowCount() {
544 return model()->GetItemCount(); 558 return model()->GetItemCount();
545 } 559 }
546 560
547 int Combobox::GetSelectedRow() { 561 int Combobox::GetSelectedRow() {
548 return selected_index_; 562 return selected_index_;
549 } 563 }
550 564
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 gfx::Insets insets = GetInsets(); 777 gfx::Insets insets = GetInsets();
764 insets += gfx::Insets(0, Textfield::kTextPadding, 0, Textfield::kTextPadding); 778 insets += gfx::Insets(0, Textfield::kTextPadding, 0, Textfield::kTextPadding);
765 779
766 gfx::ScopedCanvas scoped_canvas(canvas); 780 gfx::ScopedCanvas scoped_canvas(canvas);
767 canvas->ClipRect(GetContentsBounds()); 781 canvas->ClipRect(GetContentsBounds());
768 782
769 int x = insets.left(); 783 int x = insets.left();
770 int y = insets.top(); 784 int y = insets.top();
771 int text_height = height() - insets.height(); 785 int text_height = height() - insets.height();
772 SkColor text_color = GetNativeTheme()->GetSystemColor( 786 SkColor text_color = GetNativeTheme()->GetSystemColor(
773 enabled() ? ui::NativeTheme::kColorId_LabelEnabledColor : 787 UseMd() ? (enabled() ? ui::NativeTheme::kColorId_TextfieldDefaultColor
774 ui::NativeTheme::kColorId_LabelDisabledColor); 788 : ui::NativeTheme::kColorId_TextfieldReadOnlyColor)
789 : (enabled() ? ui::NativeTheme::kColorId_LabelEnabledColor
790 : ui::NativeTheme::kColorId_LabelDisabledColor));
775 791
776 DCHECK_GE(selected_index_, 0); 792 DCHECK_GE(selected_index_, 0);
777 DCHECK_LT(selected_index_, model()->GetItemCount()); 793 DCHECK_LT(selected_index_, model()->GetItemCount());
778 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) 794 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount())
779 selected_index_ = 0; 795 selected_index_ = 0;
780 base::string16 text = model()->GetItemAt(selected_index_); 796 base::string16 text = model()->GetItemAt(selected_index_);
781 797
782 int disclosure_arrow_offset = width() - GetArrowContainerWidth(); 798 int disclosure_arrow_offset = width() - GetArrowContainerWidth();
783 799
784 const gfx::FontList& font_list = Combobox::GetFontList(); 800 const gfx::FontList& font_list = Combobox::GetFontList();
(...skipping 23 matching lines...) Expand all
808 // This epsilon makes sure that all the aliasing pixels are slightly more 824 // This epsilon makes sure that all the aliasing pixels are slightly more
809 // than half full. Otherwise, rounding issues cause some to be considered 825 // than half full. Otherwise, rounding issues cause some to be considered
810 // slightly less than half full and come out a little lighter. 826 // slightly less than half full and come out a little lighter.
811 const SkScalar kEpsilon = 0.0001f; 827 const SkScalar kEpsilon = 0.0001f;
812 path.moveTo(x - kEpsilon, y); 828 path.moveTo(x - kEpsilon, y);
813 path.rLineTo(height, height); 829 path.rLineTo(height, height);
814 path.rLineTo(2 * kEpsilon, 0); 830 path.rLineTo(2 * kEpsilon, 0);
815 path.rLineTo(height, -height); 831 path.rLineTo(height, -height);
816 path.close(); 832 path.close();
817 SkPaint paint; 833 SkPaint paint;
818 paint.setColor(GetNativeTheme()->GetSystemColor( 834 SkColor arrow_color = GetNativeTheme()->GetSystemColor(
819 ui::NativeTheme::kColorId_ButtonEnabledColor)); 835 ui::NativeTheme::kColorId_ButtonEnabledColor);
836 // TODO(estade): share this disabled alpha value with other places that use
837 // it.
838 if (!enabled())
839 arrow_color = SkColorSetA(arrow_color, 0x61);
840 paint.setColor(arrow_color);
820 paint.setAntiAlias(true); 841 paint.setAntiAlias(true);
821 canvas->DrawPath(path, paint); 842 canvas->DrawPath(path, paint);
822 } else { 843 } else {
823 canvas->DrawImageInt(arrow_image_, arrow_bounds.x(), arrow_bounds.y()); 844 canvas->DrawImageInt(arrow_image_, arrow_bounds.x(), arrow_bounds.y());
824 } 845 }
825 } 846 }
826 847
827 void Combobox::PaintButtons(gfx::Canvas* canvas) { 848 void Combobox::PaintButtons(gfx::Canvas* canvas) {
828 DCHECK(style_ == STYLE_ACTION); 849 DCHECK(style_ == STYLE_ACTION);
829 850
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 } 989 }
969 990
970 int Combobox::GetArrowContainerWidth() const { 991 int Combobox::GetArrowContainerWidth() const {
971 int padding = style_ == STYLE_NORMAL 992 int padding = style_ == STYLE_NORMAL
972 ? PlatformStyle::kComboboxNormalArrowPadding * 2 993 ? PlatformStyle::kComboboxNormalArrowPadding * 2
973 : kActionLeftPadding + kActionRightPadding; 994 : kActionLeftPadding + kActionRightPadding;
974 return ArrowSize().width() + padding; 995 return ArrowSize().width() + padding;
975 } 996 }
976 997
977 } // namespace views 998 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/combobox/combobox.h ('k') | ui/views/controls/focusable_border.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698