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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_P); | 88 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_P); |
89 | 89 |
90 #undef MENU_IMAGE_GRID | 90 #undef MENU_IMAGE_GRID |
91 | 91 |
92 // The transparent button which holds a button state but is not rendered. | 92 // The transparent button which holds a button state but is not rendered. |
93 class TransparentButton : public CustomButton { | 93 class TransparentButton : public CustomButton { |
94 public: | 94 public: |
95 TransparentButton(ButtonListener* listener) | 95 TransparentButton(ButtonListener* listener) |
96 : CustomButton(listener) { | 96 : CustomButton(listener) { |
97 SetAnimationDuration(LabelButton::kHoverAnimationDurationMs); | 97 SetAnimationDuration(LabelButton::kHoverAnimationDurationMs); |
| 98 SetFocusable(false); |
| 99 SetAccessibilityFocusable(false); |
98 } | 100 } |
99 ~TransparentButton() override {} | 101 ~TransparentButton() override {} |
100 | 102 |
101 bool OnMousePressed(const ui::MouseEvent& mouse_event) override { | 103 bool OnMousePressed(const ui::MouseEvent& mouse_event) override { |
102 parent()->RequestFocus(); | 104 parent()->RequestFocus(); |
103 return true; | 105 return true; |
104 } | 106 } |
105 | 107 |
106 double GetAnimationValue() const { | 108 double GetAnimationValue() const { |
107 return hover_animation().GetCurrentValue(); | 109 return hover_animation().GetCurrentValue(); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 : model_(model), | 348 : model_(model), |
347 style_(STYLE_NORMAL), | 349 style_(STYLE_NORMAL), |
348 listener_(NULL), | 350 listener_(NULL), |
349 selected_index_(model_->GetDefaultIndex()), | 351 selected_index_(model_->GetDefaultIndex()), |
350 invalid_(false), | 352 invalid_(false), |
351 menu_model_adapter_(new ComboboxMenuModelAdapter(this, model)), | 353 menu_model_adapter_(new ComboboxMenuModelAdapter(this, model)), |
352 text_button_(new TransparentButton(this)), | 354 text_button_(new TransparentButton(this)), |
353 arrow_button_(new TransparentButton(this)), | 355 arrow_button_(new TransparentButton(this)), |
354 weak_ptr_factory_(this) { | 356 weak_ptr_factory_(this) { |
355 ModelChanged(); | 357 ModelChanged(); |
356 SetFocusable(true); | 358 PlatformStyle::ConfigureFocus(PlatformStyle::CONTROL::COMBOBOX, this); |
357 UpdateBorder(); | 359 UpdateBorder(); |
358 // set_background() takes ownership but takes a raw pointer. | 360 // set_background() takes ownership but takes a raw pointer. |
359 scoped_ptr<Background> b = PlatformStyle::CreateComboboxBackground(); | 361 scoped_ptr<Background> b = PlatformStyle::CreateComboboxBackground(); |
360 set_background(b.release()); | 362 set_background(b.release()); |
361 | 363 |
362 // Initialize the button images. | 364 // Initialize the button images. |
363 Button::ButtonState button_states[] = { | 365 Button::ButtonState button_states[] = { |
364 Button::STATE_DISABLED, | 366 Button::STATE_DISABLED, |
365 Button::STATE_NORMAL, | 367 Button::STATE_NORMAL, |
366 Button::STATE_HOVERED, | 368 Button::STATE_HOVERED, |
367 Button::STATE_PRESSED, | 369 Button::STATE_PRESSED, |
368 }; | 370 }; |
369 for (int i = 0; i < 2; i++) { | 371 for (int i = 0; i < 2; i++) { |
370 for (size_t state_index = 0; state_index < arraysize(button_states); | 372 for (size_t state_index = 0; state_index < arraysize(button_states); |
371 state_index++) { | 373 state_index++) { |
372 Button::ButtonState state = button_states[state_index]; | 374 Button::ButtonState state = button_states[state_index]; |
373 size_t num; | 375 size_t num; |
374 bool focused = !!i; | 376 bool focused = !!i; |
375 const int* ids = GetBodyButtonImageIds(focused, state, &num); | 377 const int* ids = GetBodyButtonImageIds(focused, state, &num); |
376 body_button_painters_[focused][state].reset( | 378 body_button_painters_[focused][state].reset( |
377 Painter::CreateImageGridPainter(ids)); | 379 Painter::CreateImageGridPainter(ids)); |
378 menu_button_images_[focused][state] = GetMenuButtonImages(focused, state); | 380 menu_button_images_[focused][state] = GetMenuButtonImages(focused, state); |
379 } | 381 } |
380 } | 382 } |
381 | 383 |
382 text_button_->SetVisible(true); | 384 text_button_->SetVisible(true); |
383 arrow_button_->SetVisible(true); | 385 arrow_button_->SetVisible(true); |
384 text_button_->SetFocusable(false); | |
385 arrow_button_->SetFocusable(false); | |
386 AddChildView(text_button_); | 386 AddChildView(text_button_); |
387 AddChildView(arrow_button_); | 387 AddChildView(arrow_button_); |
388 } | 388 } |
389 | 389 |
390 Combobox::~Combobox() { | 390 Combobox::~Combobox() { |
391 if (GetInputMethod() && selector_.get()) { | 391 if (GetInputMethod() && selector_.get()) { |
392 // Combobox should have been blurred before destroy. | 392 // Combobox should have been blurred before destroy. |
393 DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient()); | 393 DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient()); |
394 } | 394 } |
395 } | 395 } |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 return gfx::Size(width, font_list.GetHeight()); | 915 return gfx::Size(width, font_list.GetHeight()); |
916 } | 916 } |
917 | 917 |
918 PrefixSelector* Combobox::GetPrefixSelector() { | 918 PrefixSelector* Combobox::GetPrefixSelector() { |
919 if (!selector_) | 919 if (!selector_) |
920 selector_.reset(new PrefixSelector(this)); | 920 selector_.reset(new PrefixSelector(this)); |
921 return selector_.get(); | 921 return selector_.get(); |
922 } | 922 } |
923 | 923 |
924 } // namespace views | 924 } // namespace views |
OLD | NEW |