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

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

Issue 2383243002: Refactor MdFocusRing to make it easier to reuse on other controls. (Closed)
Patch Set: explicit onfocus Created 4 years, 2 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
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 16 matching lines...) Expand all
27 #include "ui/native_theme/common_theme.h" 27 #include "ui/native_theme/common_theme.h"
28 #include "ui/native_theme/native_theme.h" 28 #include "ui/native_theme/native_theme.h"
29 #include "ui/native_theme/native_theme_aura.h" 29 #include "ui/native_theme/native_theme_aura.h"
30 #include "ui/resources/grit/ui_resources.h" 30 #include "ui/resources/grit/ui_resources.h"
31 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" 31 #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
32 #include "ui/views/animation/ink_drop_highlight.h" 32 #include "ui/views/animation/ink_drop_highlight.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/focusable_border.h" 38 #include "ui/views/controls/focusable_border.h"
38 #include "ui/views/controls/menu/menu_config.h" 39 #include "ui/views/controls/menu/menu_config.h"
39 #include "ui/views/controls/menu/menu_model_adapter.h" 40 #include "ui/views/controls/menu/menu_model_adapter.h"
40 #include "ui/views/controls/menu/menu_runner.h" 41 #include "ui/views/controls/menu/menu_runner.h"
41 #include "ui/views/controls/prefix_selector.h" 42 #include "ui/views/controls/prefix_selector.h"
42 #include "ui/views/controls/textfield/textfield.h" 43 #include "ui/views/controls/textfield/textfield.h"
43 #include "ui/views/mouse_constants.h" 44 #include "ui/views/mouse_constants.h"
44 #include "ui/views/painter.h" 45 #include "ui/views/painter.h"
45 #include "ui/views/resources/grit/views_resources.h" 46 #include "ui/views/resources/grit/views_resources.h"
46 #include "ui/views/style/platform_style.h" 47 #include "ui/views/style/platform_style.h"
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 386
386 DISALLOW_COPY_AND_ASSIGN(ComboboxMenuModel); 387 DISALLOW_COPY_AND_ASSIGN(ComboboxMenuModel);
387 }; 388 };
388 389
389 //////////////////////////////////////////////////////////////////////////////// 390 ////////////////////////////////////////////////////////////////////////////////
390 // Combobox, public: 391 // Combobox, public:
391 392
392 Combobox::Combobox(ui::ComboboxModel* model, Style style) 393 Combobox::Combobox(ui::ComboboxModel* model, Style style)
393 : model_(model), 394 : model_(model),
394 style_(style), 395 style_(style),
395 listener_(NULL), 396 listener_(nullptr),
396 selected_index_(style == STYLE_ACTION ? 0 : model_->GetDefaultIndex()), 397 selected_index_(style == STYLE_ACTION ? 0 : model_->GetDefaultIndex()),
397 invalid_(false), 398 invalid_(false),
398 menu_model_(new ComboboxMenuModel(this, model)), 399 menu_model_(new ComboboxMenuModel(this, model)),
399 text_button_(new TransparentButton(this, style_ == STYLE_ACTION)), 400 text_button_(new TransparentButton(this, style_ == STYLE_ACTION)),
400 arrow_button_(new TransparentButton(this, style_ == STYLE_ACTION)), 401 arrow_button_(new TransparentButton(this, style_ == STYLE_ACTION)),
402 focus_ring_(nullptr),
401 size_to_largest_label_(style_ == STYLE_NORMAL), 403 size_to_largest_label_(style_ == STYLE_NORMAL),
402 weak_ptr_factory_(this) { 404 weak_ptr_factory_(this) {
403 ModelChanged(); 405 ModelChanged();
404 #if defined(OS_MACOSX) 406 #if defined(OS_MACOSX)
405 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); 407 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
406 #else 408 #else
407 SetFocusBehavior(FocusBehavior::ALWAYS); 409 SetFocusBehavior(FocusBehavior::ALWAYS);
408 #endif 410 #endif
409 411
410 UpdateBorder(); 412 UpdateBorder();
411 if (UseMd()) { 413 if (UseMd()) {
412 // set_background() takes ownership but takes a raw pointer. 414 // set_background() takes ownership but takes a raw pointer.
413 std::unique_ptr<Background> b = 415 std::unique_ptr<Background> b =
414 PlatformStyle::CreateComboboxBackground(GetArrowContainerWidth()); 416 PlatformStyle::CreateComboboxBackground(GetArrowContainerWidth());
415 set_background(b.release()); 417 set_background(b.release());
418 focus_ring_ = new FocusRing();
419 AddChildView(focus_ring_);
416 } 420 }
417 421
418 // Initialize the button images. 422 // Initialize the button images.
419 Button::ButtonState button_states[] = { 423 Button::ButtonState button_states[] = {
420 Button::STATE_DISABLED, 424 Button::STATE_DISABLED,
421 Button::STATE_NORMAL, 425 Button::STATE_NORMAL,
422 Button::STATE_HOVERED, 426 Button::STATE_HOVERED,
423 Button::STATE_PRESSED, 427 Button::STATE_PRESSED,
424 }; 428 };
425 for (int i = 0; i < 2; i++) { 429 for (int i = 0; i < 2; i++) {
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 } 712 }
709 } 713 }
710 714
711 void Combobox::OnFocus() { 715 void Combobox::OnFocus() {
712 if (GetInputMethod()) 716 if (GetInputMethod())
713 GetInputMethod()->SetFocusedTextInputClient(GetPrefixSelector()); 717 GetInputMethod()->SetFocusedTextInputClient(GetPrefixSelector());
714 718
715 View::OnFocus(); 719 View::OnFocus();
716 // Border renders differently when focused. 720 // Border renders differently when focused.
717 SchedulePaint(); 721 SchedulePaint();
722 if (UseMd())
723 focus_ring_->SetVisible(true);
718 } 724 }
719 725
720 void Combobox::OnBlur() { 726 void Combobox::OnBlur() {
721 if (GetInputMethod()) 727 if (GetInputMethod())
722 GetInputMethod()->DetachTextInputClient(GetPrefixSelector()); 728 GetInputMethod()->DetachTextInputClient(GetPrefixSelector());
723 729
724 if (selector_) 730 if (selector_)
725 selector_->OnViewBlur(); 731 selector_->OnViewBlur();
726 // Border renders differently when focused. 732 // Border renders differently when focused.
727 SchedulePaint(); 733 SchedulePaint();
734 if (UseMd())
sky 2016/10/03 23:53:15 Is there a reason not to delegate focus_ring_ here
Evan Stade 2016/10/04 01:04:55 No reason. Made a couple of statics to create and
735 focus_ring_->SetVisible(false);
728 } 736 }
729 737
730 void Combobox::GetAccessibleState(ui::AXViewState* state) { 738 void Combobox::GetAccessibleState(ui::AXViewState* state) {
731 state->role = ui::AX_ROLE_COMBO_BOX; 739 state->role = ui::AX_ROLE_COMBO_BOX;
732 state->name = accessible_name_; 740 state->name = accessible_name_;
733 state->value = model_->GetItemAt(selected_index_); 741 state->value = model_->GetItemAt(selected_index_);
734 state->index = selected_index_; 742 state->index = selected_index_;
735 state->count = model_->GetItemCount(); 743 state->count = model_->GetItemCount();
736 } 744 }
737 745
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 const int kMdPaddingWidth = 8; 1000 const int kMdPaddingWidth = 8;
993 int arrow_pad = UseMd() ? kMdPaddingWidth 1001 int arrow_pad = UseMd() ? kMdPaddingWidth
994 : PlatformStyle::kComboboxNormalArrowPadding; 1002 : PlatformStyle::kComboboxNormalArrowPadding;
995 int padding = style_ == STYLE_NORMAL 1003 int padding = style_ == STYLE_NORMAL
996 ? arrow_pad * 2 1004 ? arrow_pad * 2
997 : kActionLeftPadding + kActionRightPadding; 1005 : kActionLeftPadding + kActionRightPadding;
998 return ArrowSize().width() + padding; 1006 return ArrowSize().width() + padding;
999 } 1007 }
1000 1008
1001 } // namespace views 1009 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698