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

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

Issue 2627013002: MacViews: Fix combobox keyboard shortcuts. (Closed)
Patch Set: Add a comment. Created 3 years, 11 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/combobox/combobox_unittest.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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 // On Mac, navigation keys should always just show the menu first.
631 show_menu = true;
632 break;
633 #else
622 // Show the menu on F4 without modifiers. 634 // Show the menu on F4 without modifiers.
623 case ui::VKEY_F4: 635 case ui::VKEY_F4:
624 if (e.IsAltDown() || e.IsAltGrDown() || e.IsControlDown()) 636 if (e.IsAltDown() || e.IsAltGrDown() || e.IsControlDown())
625 return false; 637 return false;
626 show_menu = true; 638 show_menu = true;
627 break; 639 break;
628 640
629 // Move to the next item if any, or show the menu on Alt+Down like Windows. 641 // Move to the next item if any, or show the menu on Alt+Down like Windows.
630 case ui::VKEY_DOWN: 642 case ui::VKEY_DOWN:
631 if (e.IsAltDown()) 643 if (e.IsAltDown())
(...skipping 28 matching lines...) Expand all
660 show_menu = true; 672 show_menu = true;
661 } 673 }
662 break; 674 break;
663 675
664 case ui::VKEY_RETURN: 676 case ui::VKEY_RETURN:
665 if (style_ == STYLE_ACTION) 677 if (style_ == STYLE_ACTION)
666 OnPerformAction(); 678 OnPerformAction();
667 else 679 else
668 show_menu = true; 680 show_menu = true;
669 break; 681 break;
670 682 #endif // OS_MACOSX
671 default: 683 default:
672 return false; 684 return false;
673 } 685 }
674 686
675 if (show_menu) { 687 if (show_menu) {
676 ShowDropDownMenu(ui::MENU_SOURCE_KEYBOARD); 688 ShowDropDownMenu(ui::MENU_SOURCE_KEYBOARD);
677 } else if (new_index != selected_index_ && new_index != kNoSelection && 689 } else if (new_index != selected_index_ && new_index != kNoSelection &&
678 style_ != STYLE_ACTION) { 690 style_ != STYLE_ACTION) {
679 DCHECK(!model()->IsItemSeparatorAt(new_index)); 691 DCHECK(!model()->IsItemSeparatorAt(new_index));
680 selected_index_ = new_index; 692 selected_index_ = new_index;
681 OnPerformAction(); 693 OnPerformAction();
682 } 694 }
683 695
684 return true; 696 return true;
685 } 697 }
686 698
687 bool Combobox::OnKeyReleased(const ui::KeyEvent& e) { 699 bool Combobox::OnKeyReleased(const ui::KeyEvent& e) {
688 if (style_ != STYLE_ACTION) 700 if (style_ != STYLE_ACTION)
689 return false; // crbug.com/127520 701 return false; // crbug.com/127520
690 702
691 if (e.key_code() == ui::VKEY_SPACE && style_ == STYLE_ACTION) 703 if (e.key_code() == ui::VKEY_SPACE && style_ == STYLE_ACTION &&
704 text_button_->state() == Button::STATE_PRESSED)
692 OnPerformAction(); 705 OnPerformAction();
693 706
694 return false; 707 return false;
695 } 708 }
696 709
697 void Combobox::OnPaint(gfx::Canvas* canvas) { 710 void Combobox::OnPaint(gfx::Canvas* canvas) {
698 switch (style_) { 711 switch (style_) {
699 case STYLE_NORMAL: { 712 case STYLE_NORMAL: {
700 OnPaintBackground(canvas); 713 OnPaintBackground(canvas);
701 PaintText(canvas); 714 PaintText(canvas);
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 const int kMdPaddingWidth = 8; 1009 const int kMdPaddingWidth = 8;
997 int arrow_pad = UseMd() ? kMdPaddingWidth 1010 int arrow_pad = UseMd() ? kMdPaddingWidth
998 : PlatformStyle::kComboboxNormalArrowPadding; 1011 : PlatformStyle::kComboboxNormalArrowPadding;
999 int padding = style_ == STYLE_NORMAL 1012 int padding = style_ == STYLE_NORMAL
1000 ? arrow_pad * 2 1013 ? arrow_pad * 2
1001 : kActionLeftPadding + kActionRightPadding; 1014 : kActionLeftPadding + kActionRightPadding;
1002 return ArrowSize().width() + padding; 1015 return ArrowSize().width() + padding;
1003 } 1016 }
1004 1017
1005 } // namespace views 1018 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/combobox/combobox.h ('k') | ui/views/controls/combobox/combobox_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698