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 19 matching lines...) Expand all Loading... |
30 #include "ui/views/controls/button/label_button.h" | 30 #include "ui/views/controls/button/label_button.h" |
31 #include "ui/views/controls/combobox/combobox_listener.h" | 31 #include "ui/views/controls/combobox/combobox_listener.h" |
32 #include "ui/views/controls/focusable_border.h" | 32 #include "ui/views/controls/focusable_border.h" |
33 #include "ui/views/controls/menu/menu_config.h" | 33 #include "ui/views/controls/menu/menu_config.h" |
34 #include "ui/views/controls/menu/menu_runner.h" | 34 #include "ui/views/controls/menu/menu_runner.h" |
35 #include "ui/views/controls/prefix_selector.h" | 35 #include "ui/views/controls/prefix_selector.h" |
36 #include "ui/views/controls/textfield/textfield.h" | 36 #include "ui/views/controls/textfield/textfield.h" |
37 #include "ui/views/mouse_constants.h" | 37 #include "ui/views/mouse_constants.h" |
38 #include "ui/views/painter.h" | 38 #include "ui/views/painter.h" |
39 #include "ui/views/resources/grit/views_resources.h" | 39 #include "ui/views/resources/grit/views_resources.h" |
| 40 #include "ui/views/style/platform_style.h" |
40 #include "ui/views/widget/widget.h" | 41 #include "ui/views/widget/widget.h" |
41 | 42 |
42 namespace views { | 43 namespace views { |
43 | 44 |
44 namespace { | 45 namespace { |
45 | 46 |
46 // Menu border widths | 47 // Menu border widths |
47 const int kMenuBorderWidthLeft = 1; | 48 const int kMenuBorderWidthLeft = 1; |
48 const int kMenuBorderWidthTop = 1; | 49 const int kMenuBorderWidthTop = 1; |
49 const int kMenuBorderWidthRight = 1; | 50 const int kMenuBorderWidthRight = 1; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 const int kFocusedPressedMenuButtonImages[] = | 85 const int kFocusedPressedMenuButtonImages[] = |
85 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_P); | 86 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_P); |
86 | 87 |
87 #undef MENU_IMAGE_GRID | 88 #undef MENU_IMAGE_GRID |
88 | 89 |
89 // The transparent button which holds a button state but is not rendered. | 90 // The transparent button which holds a button state but is not rendered. |
90 class TransparentButton : public CustomButton { | 91 class TransparentButton : public CustomButton { |
91 public: | 92 public: |
92 TransparentButton(ButtonListener* listener) | 93 TransparentButton(ButtonListener* listener) |
93 : CustomButton(listener) { | 94 : CustomButton(listener) { |
| 95 SetAccessibilityFocusable(false); |
| 96 DCHECK(!IsFocusable()); |
| 97 |
94 SetAnimationDuration(LabelButton::kHoverAnimationDurationMs); | 98 SetAnimationDuration(LabelButton::kHoverAnimationDurationMs); |
95 } | 99 } |
96 ~TransparentButton() override {} | 100 ~TransparentButton() override {} |
97 | 101 |
98 bool OnMousePressed(const ui::MouseEvent& mouse_event) override { | 102 bool OnMousePressed(const ui::MouseEvent& mouse_event) override { |
99 parent()->RequestFocus(); | 103 parent()->RequestFocus(); |
100 return true; | 104 return true; |
101 } | 105 } |
102 | 106 |
103 double GetAnimationValue() const { | 107 double GetAnimationValue() const { |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 : model_(model), | 347 : model_(model), |
344 style_(STYLE_NORMAL), | 348 style_(STYLE_NORMAL), |
345 listener_(NULL), | 349 listener_(NULL), |
346 selected_index_(model_->GetDefaultIndex()), | 350 selected_index_(model_->GetDefaultIndex()), |
347 invalid_(false), | 351 invalid_(false), |
348 menu_model_adapter_(new ComboboxMenuModelAdapter(this, model)), | 352 menu_model_adapter_(new ComboboxMenuModelAdapter(this, model)), |
349 text_button_(new TransparentButton(this)), | 353 text_button_(new TransparentButton(this)), |
350 arrow_button_(new TransparentButton(this)), | 354 arrow_button_(new TransparentButton(this)), |
351 weak_ptr_factory_(this) { | 355 weak_ptr_factory_(this) { |
352 ModelChanged(); | 356 ModelChanged(); |
353 SetFocusable(true); | 357 PlatformStyle::SetControlStyleFocus(this); |
354 UpdateBorder(); | 358 UpdateBorder(); |
355 | 359 |
356 // Initialize the button images. | 360 // Initialize the button images. |
357 Button::ButtonState button_states[] = { | 361 Button::ButtonState button_states[] = { |
358 Button::STATE_DISABLED, | 362 Button::STATE_DISABLED, |
359 Button::STATE_NORMAL, | 363 Button::STATE_NORMAL, |
360 Button::STATE_HOVERED, | 364 Button::STATE_HOVERED, |
361 Button::STATE_PRESSED, | 365 Button::STATE_PRESSED, |
362 }; | 366 }; |
363 for (int i = 0; i < 2; i++) { | 367 for (int i = 0; i < 2; i++) { |
364 for (size_t state_index = 0; state_index < arraysize(button_states); | 368 for (size_t state_index = 0; state_index < arraysize(button_states); |
365 state_index++) { | 369 state_index++) { |
366 Button::ButtonState state = button_states[state_index]; | 370 Button::ButtonState state = button_states[state_index]; |
367 size_t num; | 371 size_t num; |
368 bool focused = !!i; | 372 bool focused = !!i; |
369 const int* ids = GetBodyButtonImageIds(focused, state, &num); | 373 const int* ids = GetBodyButtonImageIds(focused, state, &num); |
370 body_button_painters_[focused][state].reset( | 374 body_button_painters_[focused][state].reset( |
371 Painter::CreateImageGridPainter(ids)); | 375 Painter::CreateImageGridPainter(ids)); |
372 menu_button_images_[focused][state] = GetMenuButtonImages(focused, state); | 376 menu_button_images_[focused][state] = GetMenuButtonImages(focused, state); |
373 } | 377 } |
374 } | 378 } |
375 | 379 |
376 text_button_->SetVisible(true); | 380 text_button_->SetVisible(true); |
377 arrow_button_->SetVisible(true); | 381 arrow_button_->SetVisible(true); |
378 text_button_->SetFocusable(false); | |
379 arrow_button_->SetFocusable(false); | |
380 AddChildView(text_button_); | 382 AddChildView(text_button_); |
381 AddChildView(arrow_button_); | 383 AddChildView(arrow_button_); |
382 } | 384 } |
383 | 385 |
384 Combobox::~Combobox() { | 386 Combobox::~Combobox() { |
385 if (GetInputMethod() && selector_.get()) { | 387 if (GetInputMethod() && selector_.get()) { |
386 // Combobox should have been blurred before destroy. | 388 // Combobox should have been blurred before destroy. |
387 DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient()); | 389 DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient()); |
388 } | 390 } |
389 } | 391 } |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 return gfx::Size(width, font_list.GetHeight()); | 928 return gfx::Size(width, font_list.GetHeight()); |
927 } | 929 } |
928 | 930 |
929 PrefixSelector* Combobox::GetPrefixSelector() { | 931 PrefixSelector* Combobox::GetPrefixSelector() { |
930 if (!selector_) | 932 if (!selector_) |
931 selector_.reset(new PrefixSelector(this)); | 933 selector_.reset(new PrefixSelector(this)); |
932 return selector_.get(); | 934 return selector_.get(); |
933 } | 935 } |
934 | 936 |
935 } // namespace views | 937 } // namespace views |
OLD | NEW |