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/native_combobox_views.h" | 5 #include "ui/views/controls/combobox/native_combobox_views.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "grit/ui_resources.h" | 9 #include "grit/ui_resources.h" |
10 #include "ui/base/events/event.h" | 10 #include "ui/base/events/event.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 NativeComboboxViews::~NativeComboboxViews() { | 92 NativeComboboxViews::~NativeComboboxViews() { |
93 } | 93 } |
94 | 94 |
95 //////////////////////////////////////////////////////////////////////////////// | 95 //////////////////////////////////////////////////////////////////////////////// |
96 // NativeComboboxViews, View overrides: | 96 // NativeComboboxViews, View overrides: |
97 | 97 |
98 bool NativeComboboxViews::OnMousePressed(const ui::MouseEvent& mouse_event) { | 98 bool NativeComboboxViews::OnMousePressed(const ui::MouseEvent& mouse_event) { |
99 combobox_->RequestFocus(); | 99 combobox_->RequestFocus(); |
100 if (mouse_event.IsLeftMouseButton()) { | 100 if (mouse_event.IsLeftMouseButton()) { |
101 UpdateFromModel(); | 101 UpdateFromModel(); |
102 ShowDropDownMenu(); | 102 ShowDropDownMenu(ui::MENU_SOURCE_MOUSE); |
103 } | 103 } |
104 | 104 |
105 return true; | 105 return true; |
106 } | 106 } |
107 | 107 |
108 bool NativeComboboxViews::OnMouseDragged(const ui::MouseEvent& mouse_event) { | 108 bool NativeComboboxViews::OnMouseDragged(const ui::MouseEvent& mouse_event) { |
109 return true; | 109 return true; |
110 } | 110 } |
111 | 111 |
112 bool NativeComboboxViews::OnKeyPressed(const ui::KeyEvent& key_event) { | 112 bool NativeComboboxViews::OnKeyPressed(const ui::KeyEvent& key_event) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 void NativeComboboxViews::OnBlur() { | 174 void NativeComboboxViews::OnBlur() { |
175 NOTREACHED(); | 175 NOTREACHED(); |
176 } | 176 } |
177 | 177 |
178 ///////////////////////////////////////////////////////////////// | 178 ///////////////////////////////////////////////////////////////// |
179 // NativeComboboxViews, ui::EventHandler overrides: | 179 // NativeComboboxViews, ui::EventHandler overrides: |
180 | 180 |
181 void NativeComboboxViews::OnGestureEvent(ui::GestureEvent* gesture) { | 181 void NativeComboboxViews::OnGestureEvent(ui::GestureEvent* gesture) { |
182 if (gesture->type() == ui::ET_GESTURE_TAP) { | 182 if (gesture->type() == ui::ET_GESTURE_TAP) { |
183 UpdateFromModel(); | 183 UpdateFromModel(); |
184 ShowDropDownMenu(); | 184 ShowDropDownMenu(ui::MENU_SOURCE_TOUCH); |
185 gesture->StopPropagation(); | 185 gesture->StopPropagation(); |
186 return; | 186 return; |
187 } | 187 } |
188 View::OnGestureEvent(gesture); | 188 View::OnGestureEvent(gesture); |
189 } | 189 } |
190 | 190 |
191 ///////////////////////////////////////////////////////////////// | 191 ///////////////////////////////////////////////////////////////// |
192 // NativeComboboxViews, NativeComboboxWrapper overrides: | 192 // NativeComboboxViews, NativeComboboxWrapper overrides: |
193 | 193 |
194 void NativeComboboxViews::UpdateFromModel() { | 194 void NativeComboboxViews::UpdateFromModel() { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 SkPaint paint; | 361 SkPaint paint; |
362 // This makes the arrow subtractive. | 362 // This makes the arrow subtractive. |
363 if (combobox_->invalid()) | 363 if (combobox_->invalid()) |
364 paint.setXfermodeMode(SkXfermode::kDstOut_Mode); | 364 paint.setXfermodeMode(SkXfermode::kDstOut_Mode); |
365 canvas->DrawImageInt(*disclosure_arrow_, arrow_bounds.x(), arrow_bounds.y(), | 365 canvas->DrawImageInt(*disclosure_arrow_, arrow_bounds.x(), arrow_bounds.y(), |
366 paint); | 366 paint); |
367 | 367 |
368 canvas->Restore(); | 368 canvas->Restore(); |
369 } | 369 } |
370 | 370 |
371 void NativeComboboxViews::ShowDropDownMenu() { | 371 void NativeComboboxViews::ShowDropDownMenu(ui::MenuSourceType source_type) { |
372 | 372 |
373 if (!dropdown_list_menu_runner_.get()) | 373 if (!dropdown_list_menu_runner_.get()) |
374 UpdateFromModel(); | 374 UpdateFromModel(); |
375 | 375 |
376 // Extend the menu to the width of the combobox. | 376 // Extend the menu to the width of the combobox. |
377 MenuItemView* menu = dropdown_list_menu_runner_->GetMenu(); | 377 MenuItemView* menu = dropdown_list_menu_runner_->GetMenu(); |
378 SubmenuView* submenu = menu->CreateSubmenu(); | 378 SubmenuView* submenu = menu->CreateSubmenu(); |
379 submenu->set_minimum_preferred_width(size().width() - | 379 submenu->set_minimum_preferred_width(size().width() - |
380 (kMenuBorderWidthLeft + kMenuBorderWidthRight)); | 380 (kMenuBorderWidthLeft + kMenuBorderWidthRight)); |
381 | 381 |
382 gfx::Rect lb = GetLocalBounds(); | 382 gfx::Rect lb = GetLocalBounds(); |
383 gfx::Point menu_position(lb.origin()); | 383 gfx::Point menu_position(lb.origin()); |
384 | 384 |
385 // Inset the menu's requested position so the border of the menu lines up | 385 // Inset the menu's requested position so the border of the menu lines up |
386 // with the border of the combobox. | 386 // with the border of the combobox. |
387 menu_position.set_x(menu_position.x() + kMenuBorderWidthLeft); | 387 menu_position.set_x(menu_position.x() + kMenuBorderWidthLeft); |
388 menu_position.set_y(menu_position.y() + kMenuBorderWidthTop); | 388 menu_position.set_y(menu_position.y() + kMenuBorderWidthTop); |
389 lb.set_width(lb.width() - (kMenuBorderWidthLeft + kMenuBorderWidthRight)); | 389 lb.set_width(lb.width() - (kMenuBorderWidthLeft + kMenuBorderWidthRight)); |
390 | 390 |
391 View::ConvertPointToScreen(this, &menu_position); | 391 View::ConvertPointToScreen(this, &menu_position); |
392 if (menu_position.x() < 0) | 392 if (menu_position.x() < 0) |
393 menu_position.set_x(0); | 393 menu_position.set_x(0); |
394 | 394 |
395 gfx::Rect bounds(menu_position, lb.size()); | 395 gfx::Rect bounds(menu_position, lb.size()); |
396 | 396 |
397 dropdown_open_ = true; | 397 dropdown_open_ = true; |
398 if (dropdown_list_menu_runner_->RunMenuAt( | 398 if (dropdown_list_menu_runner_->RunMenuAt( |
399 GetWidget(), NULL, bounds, MenuItemView::TOPLEFT, | 399 GetWidget(), NULL, bounds, MenuItemView::TOPLEFT, |
400 MenuRunner::HAS_MNEMONICS) == MenuRunner::MENU_DELETED) | 400 source_type, MenuRunner::HAS_MNEMONICS) == |
| 401 MenuRunner::MENU_DELETED) |
401 return; | 402 return; |
402 dropdown_open_ = false; | 403 dropdown_open_ = false; |
403 | 404 |
404 // Need to explicitly clear mouse handler so that events get sent | 405 // Need to explicitly clear mouse handler so that events get sent |
405 // properly after the menu finishes running. If we don't do this, then | 406 // properly after the menu finishes running. If we don't do this, then |
406 // the first click to other parts of the UI is eaten. | 407 // the first click to other parts of the UI is eaten. |
407 SetMouseHandler(NULL); | 408 SetMouseHandler(NULL); |
408 } | 409 } |
409 | 410 |
410 //////////////////////////////////////////////////////////////////////////////// | 411 //////////////////////////////////////////////////////////////////////////////// |
411 // NativeComboboxWrapper, public: | 412 // NativeComboboxWrapper, public: |
412 | 413 |
413 #if defined(USE_AURA) | 414 #if defined(USE_AURA) |
414 // static | 415 // static |
415 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper( | 416 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper( |
416 Combobox* combobox) { | 417 Combobox* combobox) { |
417 return new NativeComboboxViews(combobox); | 418 return new NativeComboboxViews(combobox); |
418 } | 419 } |
419 #endif | 420 #endif |
420 | 421 |
421 } // namespace views | 422 } // namespace views |
OLD | NEW |