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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 const int kFocusedPressedMenuButtonImages[] = | 84 const int kFocusedPressedMenuButtonImages[] = |
85 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_P); | 85 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_P); |
86 | 86 |
87 #undef MENU_IMAGE_GRID | 87 #undef MENU_IMAGE_GRID |
88 | 88 |
89 // The transparent button which holds a button state but is not rendered. | 89 // The transparent button which holds a button state but is not rendered. |
90 class TransparentButton : public CustomButton { | 90 class TransparentButton : public CustomButton { |
91 public: | 91 public: |
92 TransparentButton(ButtonListener* listener) | 92 TransparentButton(ButtonListener* listener) |
93 : CustomButton(listener) { | 93 : CustomButton(listener) { |
94 SetAccessibilityFocusable(false); | |
tapted
2016/02/12 02:56:44
perhaps DCHECK(!IsFocusable()); after this? It's
karandeepb
2016/02/22 07:15:37
Done.
| |
94 SetAnimationDuration(LabelButton::kHoverAnimationDurationMs); | 95 SetAnimationDuration(LabelButton::kHoverAnimationDurationMs); |
95 } | 96 } |
96 ~TransparentButton() override {} | 97 ~TransparentButton() override {} |
97 | 98 |
98 bool OnMousePressed(const ui::MouseEvent& mouse_event) override { | 99 bool OnMousePressed(const ui::MouseEvent& mouse_event) override { |
99 parent()->RequestFocus(); | 100 parent()->RequestFocus(); |
100 return true; | 101 return true; |
101 } | 102 } |
102 | 103 |
103 double GetAnimationValue() const { | 104 double GetAnimationValue() const { |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 : model_(model), | 344 : model_(model), |
344 style_(STYLE_NORMAL), | 345 style_(STYLE_NORMAL), |
345 listener_(NULL), | 346 listener_(NULL), |
346 selected_index_(model_->GetDefaultIndex()), | 347 selected_index_(model_->GetDefaultIndex()), |
347 invalid_(false), | 348 invalid_(false), |
348 menu_model_adapter_(new ComboboxMenuModelAdapter(this, model)), | 349 menu_model_adapter_(new ComboboxMenuModelAdapter(this, model)), |
349 text_button_(new TransparentButton(this)), | 350 text_button_(new TransparentButton(this)), |
350 arrow_button_(new TransparentButton(this)), | 351 arrow_button_(new TransparentButton(this)), |
351 weak_ptr_factory_(this) { | 352 weak_ptr_factory_(this) { |
352 ModelChanged(); | 353 ModelChanged(); |
354 | |
355 #if !defined(OS_MACOSX) | |
353 SetFocusable(true); | 356 SetFocusable(true); |
357 #else | |
358 SetFocusable(false); | |
359 SetAccessibilityFocusable(true); | |
360 #endif | |
361 | |
354 UpdateBorder(); | 362 UpdateBorder(); |
355 | 363 |
356 // Initialize the button images. | 364 // Initialize the button images. |
357 Button::ButtonState button_states[] = { | 365 Button::ButtonState button_states[] = { |
358 Button::STATE_DISABLED, | 366 Button::STATE_DISABLED, |
359 Button::STATE_NORMAL, | 367 Button::STATE_NORMAL, |
360 Button::STATE_HOVERED, | 368 Button::STATE_HOVERED, |
361 Button::STATE_PRESSED, | 369 Button::STATE_PRESSED, |
362 }; | 370 }; |
363 for (int i = 0; i < 2; i++) { | 371 for (int i = 0; i < 2; i++) { |
364 for (size_t state_index = 0; state_index < arraysize(button_states); | 372 for (size_t state_index = 0; state_index < arraysize(button_states); |
365 state_index++) { | 373 state_index++) { |
366 Button::ButtonState state = button_states[state_index]; | 374 Button::ButtonState state = button_states[state_index]; |
367 size_t num; | 375 size_t num; |
368 bool focused = !!i; | 376 bool focused = !!i; |
369 const int* ids = GetBodyButtonImageIds(focused, state, &num); | 377 const int* ids = GetBodyButtonImageIds(focused, state, &num); |
370 body_button_painters_[focused][state].reset( | 378 body_button_painters_[focused][state].reset( |
371 Painter::CreateImageGridPainter(ids)); | 379 Painter::CreateImageGridPainter(ids)); |
372 menu_button_images_[focused][state] = GetMenuButtonImages(focused, state); | 380 menu_button_images_[focused][state] = GetMenuButtonImages(focused, state); |
373 } | 381 } |
374 } | 382 } |
375 | 383 |
376 text_button_->SetVisible(true); | 384 text_button_->SetVisible(true); |
377 arrow_button_->SetVisible(true); | 385 arrow_button_->SetVisible(true); |
378 text_button_->SetFocusable(false); | |
379 arrow_button_->SetFocusable(false); | |
380 AddChildView(text_button_); | 386 AddChildView(text_button_); |
381 AddChildView(arrow_button_); | 387 AddChildView(arrow_button_); |
382 } | 388 } |
383 | 389 |
384 Combobox::~Combobox() { | 390 Combobox::~Combobox() { |
385 if (GetInputMethod() && selector_.get()) { | 391 if (GetInputMethod() && selector_.get()) { |
386 // Combobox should have been blurred before destroy. | 392 // Combobox should have been blurred before destroy. |
387 DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient()); | 393 DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient()); |
388 } | 394 } |
389 } | 395 } |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
926 return gfx::Size(width, font_list.GetHeight()); | 932 return gfx::Size(width, font_list.GetHeight()); |
927 } | 933 } |
928 | 934 |
929 PrefixSelector* Combobox::GetPrefixSelector() { | 935 PrefixSelector* Combobox::GetPrefixSelector() { |
930 if (!selector_) | 936 if (!selector_) |
931 selector_.reset(new PrefixSelector(this)); | 937 selector_.reset(new PrefixSelector(this)); |
932 return selector_.get(); | 938 return selector_.get(); |
933 } | 939 } |
934 | 940 |
935 } // namespace views | 941 } // namespace views |
OLD | NEW |