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 show_menu = true; | |
| 628 break; | |
| 629 case ui::VKEY_SPACE: | |
| 630 if (style_ == STYLE_ACTION) | |
|
karandeepb
2017/01/13 08:28:57
Does STYLE_ACTION have something analogous on Coco
tapted
2017/01/13 19:06:39
STYLE_ACTION on mac is effectively NSPopupButton.
karandeepb
2017/01/16 04:26:15
Done. Although, it seems to me that the intention
tapted
2017/01/17 21:48:32
yup - and even that is likely going away -- https:
karandeepb
2017/01/18 03:09:56
Oh, that's good, should result in some code cleanu
| |
| 631 OnPerformAction(); | |
| 632 else | |
| 633 show_menu = true; | |
| 634 break; | |
| 635 #else | |
| 622 // Show the menu on F4 without modifiers. | 636 // Show the menu on F4 without modifiers. |
| 623 case ui::VKEY_F4: | 637 case ui::VKEY_F4: |
| 624 if (e.IsAltDown() || e.IsAltGrDown() || e.IsControlDown()) | 638 if (e.IsAltDown() || e.IsAltGrDown() || e.IsControlDown()) |
| 625 return false; | 639 return false; |
| 626 show_menu = true; | 640 show_menu = true; |
| 627 break; | 641 break; |
| 628 | 642 |
| 629 // Move to the next item if any, or show the menu on Alt+Down like Windows. | 643 // Move to the next item if any, or show the menu on Alt+Down like Windows. |
| 630 case ui::VKEY_DOWN: | 644 case ui::VKEY_DOWN: |
| 631 if (e.IsAltDown()) | 645 if (e.IsAltDown()) |
| 632 show_menu = true; | 646 show_menu = true; |
| 633 else | 647 else |
| 634 new_index = GetAdjacentIndex(model(), 1, selected_index_); | 648 new_index = GetAdjacentIndex(model(), 1, selected_index_); |
| 635 break; | 649 break; |
| 636 | 650 |
| 637 // Move to the end of the list. | 651 // Move to the end of the list. |
| 638 case ui::VKEY_END: | 652 case ui::VKEY_END: |
|
tapted
2017/01/13 19:06:39
I think HOME/END should be mapped. Remember we pic
karandeepb
2017/01/16 04:26:15
Ohk I din't know that Cmd+Up/Down could also be us
tapted
2017/01/17 21:48:32
yeah the mapping is to give things overriding OnKe
| |
| 639 case ui::VKEY_NEXT: // Page down. | 653 case ui::VKEY_NEXT: // Page down. |
| 640 new_index = GetAdjacentIndex(model(), -1, model()->GetItemCount()); | 654 new_index = GetAdjacentIndex(model(), -1, model()->GetItemCount()); |
| 641 break; | 655 break; |
| 642 | 656 |
| 643 // Move to the beginning of the list. | 657 // Move to the beginning of the list. |
| 644 case ui::VKEY_HOME: | 658 case ui::VKEY_HOME: |
| 645 case ui::VKEY_PRIOR: // Page up. | 659 case ui::VKEY_PRIOR: // Page up. |
| 646 new_index = GetAdjacentIndex(model(), 1, -1); | 660 new_index = GetAdjacentIndex(model(), 1, -1); |
| 647 break; | 661 break; |
| 648 | 662 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 660 show_menu = true; | 674 show_menu = true; |
| 661 } | 675 } |
| 662 break; | 676 break; |
| 663 | 677 |
| 664 case ui::VKEY_RETURN: | 678 case ui::VKEY_RETURN: |
| 665 if (style_ == STYLE_ACTION) | 679 if (style_ == STYLE_ACTION) |
| 666 OnPerformAction(); | 680 OnPerformAction(); |
| 667 else | 681 else |
| 668 show_menu = true; | 682 show_menu = true; |
| 669 break; | 683 break; |
| 670 | 684 #endif // OS_MACOSX |
| 671 default: | 685 default: |
| 672 return false; | 686 return false; |
| 673 } | 687 } |
| 674 | 688 |
| 675 if (show_menu) { | 689 if (show_menu) { |
| 676 ShowDropDownMenu(ui::MENU_SOURCE_KEYBOARD); | 690 ShowDropDownMenu(ui::MENU_SOURCE_KEYBOARD); |
| 677 } else if (new_index != selected_index_ && new_index != kNoSelection && | 691 } else if (new_index != selected_index_ && new_index != kNoSelection && |
| 678 style_ != STYLE_ACTION) { | 692 style_ != STYLE_ACTION) { |
| 679 DCHECK(!model()->IsItemSeparatorAt(new_index)); | 693 DCHECK(!model()->IsItemSeparatorAt(new_index)); |
| 680 selected_index_ = new_index; | 694 selected_index_ = new_index; |
| 681 OnPerformAction(); | 695 OnPerformAction(); |
| 682 } | 696 } |
| 683 | 697 |
| 684 return true; | 698 return true; |
| 685 } | 699 } |
| 686 | 700 |
| 687 bool Combobox::OnKeyReleased(const ui::KeyEvent& e) { | 701 bool Combobox::OnKeyReleased(const ui::KeyEvent& e) { |
| 688 if (style_ != STYLE_ACTION) | 702 if (style_ != STYLE_ACTION) |
| 689 return false; // crbug.com/127520 | 703 return false; // crbug.com/127520 |
| 690 | 704 |
| 691 if (e.key_code() == ui::VKEY_SPACE && style_ == STYLE_ACTION) | 705 if (e.key_code() == ui::VKEY_SPACE && style_ == STYLE_ACTION && |
| 706 text_button_->state() == Button::STATE_PRESSED) | |
|
tapted
2017/01/13 19:06:39
(does showing the menu instead manage to swallow t
karandeepb
2017/01/16 04:26:16
So the key release is swallowed when the menu is s
| |
| 692 OnPerformAction(); | 707 OnPerformAction(); |
| 693 | 708 |
| 694 return false; | 709 return false; |
| 695 } | 710 } |
| 696 | 711 |
| 697 void Combobox::OnPaint(gfx::Canvas* canvas) { | 712 void Combobox::OnPaint(gfx::Canvas* canvas) { |
| 698 switch (style_) { | 713 switch (style_) { |
| 699 case STYLE_NORMAL: { | 714 case STYLE_NORMAL: { |
| 700 OnPaintBackground(canvas); | 715 OnPaintBackground(canvas); |
| 701 PaintText(canvas); | 716 PaintText(canvas); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 996 const int kMdPaddingWidth = 8; | 1011 const int kMdPaddingWidth = 8; |
| 997 int arrow_pad = UseMd() ? kMdPaddingWidth | 1012 int arrow_pad = UseMd() ? kMdPaddingWidth |
| 998 : PlatformStyle::kComboboxNormalArrowPadding; | 1013 : PlatformStyle::kComboboxNormalArrowPadding; |
| 999 int padding = style_ == STYLE_NORMAL | 1014 int padding = style_ == STYLE_NORMAL |
| 1000 ? arrow_pad * 2 | 1015 ? arrow_pad * 2 |
| 1001 : kActionLeftPadding + kActionRightPadding; | 1016 : kActionLeftPadding + kActionRightPadding; |
| 1002 return ArrowSize().width() + padding; | 1017 return ArrowSize().width() + padding; |
| 1003 } | 1018 } |
| 1004 | 1019 |
| 1005 } // namespace views | 1020 } // namespace views |
| OLD | NEW |