Chromium Code Reviews| 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 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 size(), GetInkDropCenterBasedOnLastEvent(), | 154 size(), GetInkDropCenterBasedOnLastEvent(), |
| 155 GetNativeTheme()->GetSystemColor( | 155 GetNativeTheme()->GetSystemColor( |
| 156 ui::NativeTheme::kColorId_LabelEnabledColor), | 156 ui::NativeTheme::kColorId_LabelEnabledColor), |
| 157 ink_drop_visible_opacity())); | 157 ink_drop_visible_opacity())); |
| 158 } | 158 } |
| 159 | 159 |
| 160 private: | 160 private: |
| 161 DISALLOW_COPY_AND_ASSIGN(TransparentButton); | 161 DISALLOW_COPY_AND_ASSIGN(TransparentButton); |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 #if !defined(OS_MACOSX) | |
| 164 // Returns the next or previous valid index (depending on |increment|'s value). | 165 // Returns the next or previous valid index (depending on |increment|'s value). |
| 165 // Skips separator or disabled indices. Returns -1 if there is no valid adjacent | 166 // Skips separator or disabled indices. Returns -1 if there is no valid adjacent |
| 166 // index. | 167 // index. |
| 167 int GetAdjacentIndex(ui::ComboboxModel* model, int increment, int index) { | 168 int GetAdjacentIndex(ui::ComboboxModel* model, int increment, int index) { |
| 168 DCHECK(increment == -1 || increment == 1); | 169 DCHECK(increment == -1 || increment == 1); |
| 169 | 170 |
| 170 index += increment; | 171 index += increment; |
| 171 while (index >= 0 && index < model->GetItemCount()) { | 172 while (index >= 0 && index < model->GetItemCount()) { |
| 172 if (!model->IsItemSeparatorAt(index) || !model->IsItemEnabledAt(index)) | 173 if (!model->IsItemSeparatorAt(index) || !model->IsItemEnabledAt(index)) |
| 173 return index; | 174 return index; |
| 174 index += increment; | 175 index += increment; |
| 175 } | 176 } |
| 176 return kNoSelection; | 177 return kNoSelection; |
| 177 } | 178 } |
| 179 #endif | |
| 178 | 180 |
| 179 // Returns the image resource ids of an array for the body button. | 181 // Returns the image resource ids of an array for the body button. |
| 180 // | 182 // |
| 181 // TODO(hajimehoshi): This function should return the images for the 'disabled' | 183 // TODO(hajimehoshi): This function should return the images for the 'disabled' |
| 182 // status. (crbug/270052) | 184 // status. (crbug/270052) |
| 183 const int* GetBodyButtonImageIds(bool focused, | 185 const int* GetBodyButtonImageIds(bool focused, |
| 184 Button::ButtonState state, | 186 Button::ButtonState state, |
| 185 size_t* num) { | 187 size_t* num) { |
| 186 DCHECK(num); | 188 DCHECK(num); |
| 187 *num = 9; | 189 *num = 9; |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 DCHECK_EQ(e.type(), ui::ET_KEY_PRESSED); | 614 DCHECK_EQ(e.type(), ui::ET_KEY_PRESSED); |
| 613 | 615 |
| 614 DCHECK_GE(selected_index_, 0); | 616 DCHECK_GE(selected_index_, 0); |
| 615 DCHECK_LT(selected_index_, model()->GetItemCount()); | 617 DCHECK_LT(selected_index_, model()->GetItemCount()); |
| 616 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) | 618 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) |
| 617 selected_index_ = 0; | 619 selected_index_ = 0; |
| 618 | 620 |
| 619 bool show_menu = false; | 621 bool show_menu = false; |
| 620 int new_index = kNoSelection; | 622 int new_index = kNoSelection; |
| 621 switch (e.key_code()) { | 623 switch (e.key_code()) { |
| 624 #if defined(OS_MACOSX) | |
| 625 case ui::VKEY_DOWN: | |
| 626 case ui::VKEY_UP: | |
| 627 case ui::VKEY_SPACE: | |
| 628 case ui::VKEY_HOME: | |
| 629 case ui::VKEY_END: | |
| 630 show_menu = true; | |
|
tapted
2017/01/17 21:48:32
nit: comment like "On Mac, navigation keys should
karandeepb
2017/01/18 03:09:56
Done.
| |
| 631 break; | |
| 632 #else | |
| 622 // Show the menu on F4 without modifiers. | 633 // Show the menu on F4 without modifiers. |
| 623 case ui::VKEY_F4: | 634 case ui::VKEY_F4: |
| 624 if (e.IsAltDown() || e.IsAltGrDown() || e.IsControlDown()) | 635 if (e.IsAltDown() || e.IsAltGrDown() || e.IsControlDown()) |
| 625 return false; | 636 return false; |
| 626 show_menu = true; | 637 show_menu = true; |
| 627 break; | 638 break; |
| 628 | 639 |
| 629 // Move to the next item if any, or show the menu on Alt+Down like Windows. | 640 // Move to the next item if any, or show the menu on Alt+Down like Windows. |
| 630 case ui::VKEY_DOWN: | 641 case ui::VKEY_DOWN: |
| 631 if (e.IsAltDown()) | 642 if (e.IsAltDown()) |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 660 show_menu = true; | 671 show_menu = true; |
| 661 } | 672 } |
| 662 break; | 673 break; |
| 663 | 674 |
| 664 case ui::VKEY_RETURN: | 675 case ui::VKEY_RETURN: |
| 665 if (style_ == STYLE_ACTION) | 676 if (style_ == STYLE_ACTION) |
| 666 OnPerformAction(); | 677 OnPerformAction(); |
| 667 else | 678 else |
| 668 show_menu = true; | 679 show_menu = true; |
| 669 break; | 680 break; |
| 670 | 681 #endif // OS_MACOSX |
| 671 default: | 682 default: |
| 672 return false; | 683 return false; |
| 673 } | 684 } |
| 674 | 685 |
| 675 if (show_menu) { | 686 if (show_menu) { |
| 676 ShowDropDownMenu(ui::MENU_SOURCE_KEYBOARD); | 687 ShowDropDownMenu(ui::MENU_SOURCE_KEYBOARD); |
| 677 } else if (new_index != selected_index_ && new_index != kNoSelection && | 688 } else if (new_index != selected_index_ && new_index != kNoSelection && |
| 678 style_ != STYLE_ACTION) { | 689 style_ != STYLE_ACTION) { |
| 679 DCHECK(!model()->IsItemSeparatorAt(new_index)); | 690 DCHECK(!model()->IsItemSeparatorAt(new_index)); |
| 680 selected_index_ = new_index; | 691 selected_index_ = new_index; |
| 681 OnPerformAction(); | 692 OnPerformAction(); |
| 682 } | 693 } |
| 683 | 694 |
| 684 return true; | 695 return true; |
| 685 } | 696 } |
| 686 | 697 |
| 687 bool Combobox::OnKeyReleased(const ui::KeyEvent& e) { | 698 bool Combobox::OnKeyReleased(const ui::KeyEvent& e) { |
| 688 if (style_ != STYLE_ACTION) | 699 if (style_ != STYLE_ACTION) |
| 689 return false; // crbug.com/127520 | 700 return false; // crbug.com/127520 |
| 690 | 701 |
| 691 if (e.key_code() == ui::VKEY_SPACE && style_ == STYLE_ACTION) | 702 if (e.key_code() == ui::VKEY_SPACE && style_ == STYLE_ACTION && |
| 703 text_button_->state() == Button::STATE_PRESSED) | |
| 692 OnPerformAction(); | 704 OnPerformAction(); |
| 693 | 705 |
| 694 return false; | 706 return false; |
| 695 } | 707 } |
| 696 | 708 |
| 697 void Combobox::OnPaint(gfx::Canvas* canvas) { | 709 void Combobox::OnPaint(gfx::Canvas* canvas) { |
| 698 switch (style_) { | 710 switch (style_) { |
| 699 case STYLE_NORMAL: { | 711 case STYLE_NORMAL: { |
| 700 OnPaintBackground(canvas); | 712 OnPaintBackground(canvas); |
| 701 PaintText(canvas); | 713 PaintText(canvas); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 996 const int kMdPaddingWidth = 8; | 1008 const int kMdPaddingWidth = 8; |
| 997 int arrow_pad = UseMd() ? kMdPaddingWidth | 1009 int arrow_pad = UseMd() ? kMdPaddingWidth |
| 998 : PlatformStyle::kComboboxNormalArrowPadding; | 1010 : PlatformStyle::kComboboxNormalArrowPadding; |
| 999 int padding = style_ == STYLE_NORMAL | 1011 int padding = style_ == STYLE_NORMAL |
| 1000 ? arrow_pad * 2 | 1012 ? arrow_pad * 2 |
| 1001 : kActionLeftPadding + kActionRightPadding; | 1013 : kActionLeftPadding + kActionRightPadding; |
| 1002 return ArrowSize().width() + padding; | 1014 return ArrowSize().width() + padding; |
| 1003 } | 1015 } |
| 1004 | 1016 |
| 1005 } // namespace views | 1017 } // namespace views |
| OLD | NEW |