| OLD | NEW |
| 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_node_data.h" | 14 #include "ui/accessibility/ax_node_data.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/material_design/material_design_controller.h" | 17 #include "ui/base/material_design/material_design_controller.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/animation/flood_fill_ink_drop_ripple.h" | |
| 31 #include "ui/views/animation/ink_drop_highlight.h" | 30 #include "ui/views/animation/ink_drop_highlight.h" |
| 32 #include "ui/views/animation/ink_drop_impl.h" | 31 #include "ui/views/animation/ink_drop_impl.h" |
| 32 #include "ui/views/animation/ink_drop_ripple.h" |
| 33 #include "ui/views/background.h" | 33 #include "ui/views/background.h" |
| 34 #include "ui/views/controls/button/custom_button.h" | 34 #include "ui/views/controls/button/custom_button.h" |
| 35 #include "ui/views/controls/button/label_button.h" | 35 #include "ui/views/controls/button/label_button.h" |
| 36 #include "ui/views/controls/combobox/combobox_listener.h" | 36 #include "ui/views/controls/combobox/combobox_listener.h" |
| 37 #include "ui/views/controls/focus_ring.h" | 37 #include "ui/views/controls/focus_ring.h" |
| 38 #include "ui/views/controls/focusable_border.h" | 38 #include "ui/views/controls/focusable_border.h" |
| 39 #include "ui/views/controls/menu/menu_config.h" | 39 #include "ui/views/controls/menu/menu_config.h" |
| 40 #include "ui/views/controls/menu/menu_runner.h" | 40 #include "ui/views/controls/menu/menu_runner.h" |
| 41 #include "ui/views/controls/prefix_selector.h" | 41 #include "ui/views/controls/prefix_selector.h" |
| 42 #include "ui/views/controls/textfield/textfield.h" | 42 #include "ui/views/controls/textfield/textfield.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_H); | 88 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_H); |
| 89 const int kFocusedPressedMenuButtonImages[] = | 89 const int kFocusedPressedMenuButtonImages[] = |
| 90 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_P); | 90 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_P); |
| 91 | 91 |
| 92 #undef MENU_IMAGE_GRID | 92 #undef MENU_IMAGE_GRID |
| 93 | 93 |
| 94 bool UseMd() { | 94 bool UseMd() { |
| 95 return ui::MaterialDesignController::IsSecondaryUiMaterial(); | 95 return ui::MaterialDesignController::IsSecondaryUiMaterial(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 SkColor GetTextColorForEnableState(bool enabled, ui::NativeTheme* theme) { |
| 99 return style::GetColor(style::CONTEXT_TEXTFIELD, |
| 100 enabled ? style::STYLE_PRIMARY : style::STYLE_DISABLED, |
| 101 theme); |
| 102 } |
| 103 |
| 98 gfx::Rect PositionArrowWithinContainer(const gfx::Rect& container_bounds, | 104 gfx::Rect PositionArrowWithinContainer(const gfx::Rect& container_bounds, |
| 99 const gfx::Size& arrow_size, | 105 const gfx::Size& arrow_size, |
| 100 Combobox::Style style) { | 106 Combobox::Style style) { |
| 101 gfx::Rect bounds(container_bounds); | 107 gfx::Rect bounds(container_bounds); |
| 102 if (style == Combobox::STYLE_ACTION) { | 108 if (style == Combobox::STYLE_ACTION) { |
| 103 // This positions the arrow horizontally. The later call to | 109 // This positions the arrow horizontally. The later call to |
| 104 // ClampToCenteredSize will position it vertically without touching the | 110 // ClampToCenteredSize will position it vertically without touching the |
| 105 // horizontal position. | 111 // horizontal position. |
| 106 bounds.Inset(kActionLeftPadding, 0, kActionRightPadding, 0); | 112 bounds.Inset(kActionLeftPadding, 0, kActionRightPadding, 0); |
| 107 DCHECK_EQ(bounds.width(), arrow_size.width()); | 113 DCHECK_EQ(bounds.width(), arrow_size.width()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 135 // platforms they do. | 141 // platforms they do. |
| 136 parent()->RequestFocus(); | 142 parent()->RequestFocus(); |
| 137 #endif | 143 #endif |
| 138 return CustomButton::OnMousePressed(mouse_event); | 144 return CustomButton::OnMousePressed(mouse_event); |
| 139 } | 145 } |
| 140 | 146 |
| 141 double GetAnimationValue() const { | 147 double GetAnimationValue() const { |
| 142 return hover_animation().GetCurrentValue(); | 148 return hover_animation().GetCurrentValue(); |
| 143 } | 149 } |
| 144 | 150 |
| 145 // Overridden from InkDropHost: | 151 // InkDropHost: |
| 146 std::unique_ptr<InkDrop> CreateInkDrop() override { | 152 std::unique_ptr<InkDrop> CreateInkDrop() override { |
| 147 std::unique_ptr<views::InkDropImpl> ink_drop = CreateDefaultInkDropImpl(); | 153 std::unique_ptr<views::InkDropImpl> ink_drop = CreateDefaultInkDropImpl(); |
| 148 ink_drop->SetShowHighlightOnHover(false); | 154 ink_drop->SetShowHighlightOnHover(false); |
| 149 return std::move(ink_drop); | 155 return std::move(ink_drop); |
| 150 } | 156 } |
| 151 | 157 |
| 152 std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override { | 158 std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override { |
| 153 return std::unique_ptr<views::InkDropRipple>( | 159 return CreateFloodFillInkDropRipple(); |
| 154 new views::FloodFillInkDropRipple( | 160 } |
| 155 size(), GetInkDropCenterBasedOnLastEvent(), | 161 |
| 156 GetNativeTheme()->GetSystemColor( | 162 SkColor GetInkDropBaseColor() const override { |
| 157 ui::NativeTheme::kColorId_LabelEnabledColor), | 163 return GetNativeTheme()->GetSystemColor( |
| 158 ink_drop_visible_opacity())); | 164 ui::NativeTheme::kColorId_LabelEnabledColor); |
| 159 } | 165 } |
| 160 | 166 |
| 161 private: | 167 private: |
| 162 DISALLOW_COPY_AND_ASSIGN(TransparentButton); | 168 DISALLOW_COPY_AND_ASSIGN(TransparentButton); |
| 163 }; | 169 }; |
| 164 | 170 |
| 165 #if !defined(OS_MACOSX) | 171 #if !defined(OS_MACOSX) |
| 166 // Returns the next or previous valid index (depending on |increment|'s value). | 172 // Returns the next or previous valid index (depending on |increment|'s value). |
| 167 // Skips separator or disabled indices. Returns -1 if there is no valid adjacent | 173 // Skips separator or disabled indices. Returns -1 if there is no valid adjacent |
| 168 // index. | 174 // index. |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 void Combobox::PaintText(gfx::Canvas* canvas) { | 814 void Combobox::PaintText(gfx::Canvas* canvas) { |
| 809 gfx::Insets insets = GetInsets(); | 815 gfx::Insets insets = GetInsets(); |
| 810 insets += gfx::Insets(0, Textfield::kTextPadding, 0, Textfield::kTextPadding); | 816 insets += gfx::Insets(0, Textfield::kTextPadding, 0, Textfield::kTextPadding); |
| 811 | 817 |
| 812 gfx::ScopedCanvas scoped_canvas(canvas); | 818 gfx::ScopedCanvas scoped_canvas(canvas); |
| 813 canvas->ClipRect(GetContentsBounds()); | 819 canvas->ClipRect(GetContentsBounds()); |
| 814 | 820 |
| 815 int x = insets.left(); | 821 int x = insets.left(); |
| 816 int y = insets.top(); | 822 int y = insets.top(); |
| 817 int text_height = height() - insets.height(); | 823 int text_height = height() - insets.height(); |
| 818 SkColor text_color = GetNativeTheme()->GetSystemColor( | 824 SkColor text_color = GetTextColorForEnableState(enabled(), GetNativeTheme()); |
| 819 UseMd() ? (enabled() ? ui::NativeTheme::kColorId_TextfieldDefaultColor | |
| 820 : ui::NativeTheme::kColorId_TextfieldReadOnlyColor) | |
| 821 : (enabled() ? ui::NativeTheme::kColorId_LabelEnabledColor | |
| 822 : ui::NativeTheme::kColorId_LabelDisabledColor)); | |
| 823 | |
| 824 DCHECK_GE(selected_index_, 0); | 825 DCHECK_GE(selected_index_, 0); |
| 825 DCHECK_LT(selected_index_, model()->GetItemCount()); | 826 DCHECK_LT(selected_index_, model()->GetItemCount()); |
| 826 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) | 827 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) |
| 827 selected_index_ = 0; | 828 selected_index_ = 0; |
| 828 base::string16 text = model()->GetItemAt(selected_index_); | 829 base::string16 text = model()->GetItemAt(selected_index_); |
| 829 | 830 |
| 830 int disclosure_arrow_offset = width() - GetArrowContainerWidth(); | 831 int disclosure_arrow_offset = width() - GetArrowContainerWidth(); |
| 831 | 832 |
| 832 const gfx::FontList& font_list = Combobox::GetFontList(); | 833 const gfx::FontList& font_list = Combobox::GetFontList(); |
| 833 int text_width = gfx::GetStringWidth(text, font_list); | 834 int text_width = gfx::GetStringWidth(text, font_list); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 856 // This epsilon makes sure that all the aliasing pixels are slightly more | 857 // This epsilon makes sure that all the aliasing pixels are slightly more |
| 857 // than half full. Otherwise, rounding issues cause some to be considered | 858 // than half full. Otherwise, rounding issues cause some to be considered |
| 858 // slightly less than half full and come out a little lighter. | 859 // slightly less than half full and come out a little lighter. |
| 859 const SkScalar kEpsilon = 0.0001f; | 860 const SkScalar kEpsilon = 0.0001f; |
| 860 path.moveTo(x - kEpsilon, y); | 861 path.moveTo(x - kEpsilon, y); |
| 861 path.rLineTo(height, height); | 862 path.rLineTo(height, height); |
| 862 path.rLineTo(2 * kEpsilon, 0); | 863 path.rLineTo(2 * kEpsilon, 0); |
| 863 path.rLineTo(height, -height); | 864 path.rLineTo(height, -height); |
| 864 path.close(); | 865 path.close(); |
| 865 cc::PaintFlags flags; | 866 cc::PaintFlags flags; |
| 866 SkColor arrow_color = GetNativeTheme()->GetSystemColor( | 867 SkColor arrow_color = GetTextColorForEnableState(true, GetNativeTheme()); |
| 867 ui::NativeTheme::kColorId_ButtonEnabledColor); | |
| 868 if (!enabled()) | 868 if (!enabled()) |
| 869 arrow_color = SkColorSetA(arrow_color, gfx::kDisabledControlAlpha); | 869 arrow_color = SkColorSetA(arrow_color, gfx::kDisabledControlAlpha); |
| 870 flags.setColor(arrow_color); | 870 flags.setColor(arrow_color); |
| 871 flags.setAntiAlias(true); | 871 flags.setAntiAlias(true); |
| 872 canvas->DrawPath(path, flags); | 872 canvas->DrawPath(path, flags); |
| 873 } else { | 873 } else { |
| 874 canvas->DrawImageInt(arrow_image_, arrow_bounds.x(), arrow_bounds.y()); | 874 canvas->DrawImageInt(arrow_image_, arrow_bounds.x(), arrow_bounds.y()); |
| 875 } | 875 } |
| 876 } | 876 } |
| 877 | 877 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 constexpr int kMdPaddingWidth = 8; | 1014 constexpr int kMdPaddingWidth = 8; |
| 1015 constexpr int kNormalPaddingWidth = 7; | 1015 constexpr int kNormalPaddingWidth = 7; |
| 1016 int arrow_pad = UseMd() ? kMdPaddingWidth : kNormalPaddingWidth; | 1016 int arrow_pad = UseMd() ? kMdPaddingWidth : kNormalPaddingWidth; |
| 1017 int padding = style_ == STYLE_NORMAL | 1017 int padding = style_ == STYLE_NORMAL |
| 1018 ? arrow_pad * 2 | 1018 ? arrow_pad * 2 |
| 1019 : kActionLeftPadding + kActionRightPadding; | 1019 : kActionLeftPadding + kActionRightPadding; |
| 1020 return ArrowSize().width() + padding; | 1020 return ArrowSize().width() + padding; |
| 1021 } | 1021 } |
| 1022 | 1022 |
| 1023 } // namespace views | 1023 } // namespace views |
| OLD | NEW |