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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 const int kFocusedPressedMenuButtonImages[] = | 87 const int kFocusedPressedMenuButtonImages[] = |
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 SetFocusBehavior(views::View::FocusBehavior::NEVER); |
97 SetAnimationDuration(LabelButton::kHoverAnimationDurationMs); | 98 SetAnimationDuration(LabelButton::kHoverAnimationDurationMs); |
98 } | 99 } |
99 ~TransparentButton() override {} | 100 ~TransparentButton() override {} |
100 | 101 |
101 bool OnMousePressed(const ui::MouseEvent& mouse_event) override { | 102 bool OnMousePressed(const ui::MouseEvent& mouse_event) override { |
102 parent()->RequestFocus(); | 103 parent()->RequestFocus(); |
103 return true; | 104 return true; |
104 } | 105 } |
105 | 106 |
106 double GetAnimationValue() const { | 107 double GetAnimationValue() const { |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 : model_(model), | 347 : model_(model), |
347 style_(STYLE_NORMAL), | 348 style_(STYLE_NORMAL), |
348 listener_(NULL), | 349 listener_(NULL), |
349 selected_index_(model_->GetDefaultIndex()), | 350 selected_index_(model_->GetDefaultIndex()), |
350 invalid_(false), | 351 invalid_(false), |
351 menu_model_adapter_(new ComboboxMenuModelAdapter(this, model)), | 352 menu_model_adapter_(new ComboboxMenuModelAdapter(this, model)), |
352 text_button_(new TransparentButton(this)), | 353 text_button_(new TransparentButton(this)), |
353 arrow_button_(new TransparentButton(this)), | 354 arrow_button_(new TransparentButton(this)), |
354 weak_ptr_factory_(this) { | 355 weak_ptr_factory_(this) { |
355 ModelChanged(); | 356 ModelChanged(); |
356 SetFocusable(true); | 357 #if defined(OS_MACOSX) |
| 358 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
| 359 #else |
| 360 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 361 #endif |
357 UpdateBorder(); | 362 UpdateBorder(); |
358 // set_background() takes ownership but takes a raw pointer. | 363 // set_background() takes ownership but takes a raw pointer. |
359 std::unique_ptr<Background> b = PlatformStyle::CreateComboboxBackground(); | 364 std::unique_ptr<Background> b = PlatformStyle::CreateComboboxBackground(); |
360 set_background(b.release()); | 365 set_background(b.release()); |
361 | 366 |
362 // Initialize the button images. | 367 // Initialize the button images. |
363 Button::ButtonState button_states[] = { | 368 Button::ButtonState button_states[] = { |
364 Button::STATE_DISABLED, | 369 Button::STATE_DISABLED, |
365 Button::STATE_NORMAL, | 370 Button::STATE_NORMAL, |
366 Button::STATE_HOVERED, | 371 Button::STATE_HOVERED, |
367 Button::STATE_PRESSED, | 372 Button::STATE_PRESSED, |
368 }; | 373 }; |
369 for (int i = 0; i < 2; i++) { | 374 for (int i = 0; i < 2; i++) { |
370 for (size_t state_index = 0; state_index < arraysize(button_states); | 375 for (size_t state_index = 0; state_index < arraysize(button_states); |
371 state_index++) { | 376 state_index++) { |
372 Button::ButtonState state = button_states[state_index]; | 377 Button::ButtonState state = button_states[state_index]; |
373 size_t num; | 378 size_t num; |
374 bool focused = !!i; | 379 bool focused = !!i; |
375 const int* ids = GetBodyButtonImageIds(focused, state, &num); | 380 const int* ids = GetBodyButtonImageIds(focused, state, &num); |
376 body_button_painters_[focused][state].reset( | 381 body_button_painters_[focused][state].reset( |
377 Painter::CreateImageGridPainter(ids)); | 382 Painter::CreateImageGridPainter(ids)); |
378 menu_button_images_[focused][state] = GetMenuButtonImages(focused, state); | 383 menu_button_images_[focused][state] = GetMenuButtonImages(focused, state); |
379 } | 384 } |
380 } | 385 } |
381 | 386 |
382 text_button_->SetVisible(true); | 387 text_button_->SetVisible(true); |
383 arrow_button_->SetVisible(true); | 388 arrow_button_->SetVisible(true); |
384 text_button_->SetFocusable(false); | |
385 arrow_button_->SetFocusable(false); | |
386 AddChildView(text_button_); | 389 AddChildView(text_button_); |
387 AddChildView(arrow_button_); | 390 AddChildView(arrow_button_); |
388 } | 391 } |
389 | 392 |
390 Combobox::~Combobox() { | 393 Combobox::~Combobox() { |
391 if (GetInputMethod() && selector_.get()) { | 394 if (GetInputMethod() && selector_.get()) { |
392 // Combobox should have been blurred before destroy. | 395 // Combobox should have been blurred before destroy. |
393 DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient()); | 396 DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient()); |
394 } | 397 } |
395 } | 398 } |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 return gfx::Size(width, font_list.GetHeight()); | 919 return gfx::Size(width, font_list.GetHeight()); |
917 } | 920 } |
918 | 921 |
919 PrefixSelector* Combobox::GetPrefixSelector() { | 922 PrefixSelector* Combobox::GetPrefixSelector() { |
920 if (!selector_) | 923 if (!selector_) |
921 selector_.reset(new PrefixSelector(this)); | 924 selector_.reset(new PrefixSelector(this)); |
922 return selector_.get(); | 925 return selector_.get(); |
923 } | 926 } |
924 | 927 |
925 } // namespace views | 928 } // namespace views |
OLD | NEW |