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/keycodes/keyboard_codes.h" | 10 #include "ui/base/keycodes/keyboard_codes.h" |
| 11 #include "ui/base/event.h" |
11 #include "ui/base/models/combobox_model.h" | 12 #include "ui/base/models/combobox_model.h" |
12 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
14 #include "ui/gfx/font.h" | 15 #include "ui/gfx/font.h" |
15 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
16 #include "ui/gfx/path.h" | 17 #include "ui/gfx/path.h" |
17 #include "ui/views/background.h" | 18 #include "ui/views/background.h" |
18 #include "ui/views/border.h" | 19 #include "ui/views/border.h" |
19 #include "ui/views/controls/combobox/combobox.h" | 20 #include "ui/views/controls/combobox/combobox.h" |
20 #include "ui/views/controls/focusable_border.h" | 21 #include "ui/views/controls/focusable_border.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 ui::GestureStatus NativeComboboxViews::OnGestureEvent( | 89 ui::GestureStatus NativeComboboxViews::OnGestureEvent( |
89 const views::GestureEvent& gesture_event) { | 90 const views::GestureEvent& gesture_event) { |
90 if (gesture_event.type() == ui::ET_GESTURE_TAP) { | 91 if (gesture_event.type() == ui::ET_GESTURE_TAP) { |
91 UpdateFromModel(); | 92 UpdateFromModel(); |
92 ShowDropDownMenu(); | 93 ShowDropDownMenu(); |
93 return ui::GESTURE_STATUS_CONSUMED; | 94 return ui::GESTURE_STATUS_CONSUMED; |
94 } | 95 } |
95 return View::OnGestureEvent(gesture_event); | 96 return View::OnGestureEvent(gesture_event); |
96 } | 97 } |
97 | 98 |
98 bool NativeComboboxViews::OnKeyPressed(const views::KeyEvent& key_event) { | 99 bool NativeComboboxViews::OnKeyPressed(const ui::KeyEvent& key_event) { |
99 // TODO(oshima): handle IME. | 100 // TODO(oshima): handle IME. |
100 DCHECK_EQ(key_event.type(), ui::ET_KEY_PRESSED); | 101 DCHECK_EQ(key_event.type(), ui::ET_KEY_PRESSED); |
101 | 102 |
102 // Check if we are in the default state (-1) and set to first item. | 103 // Check if we are in the default state (-1) and set to first item. |
103 if (selected_index_ == -1) | 104 if (selected_index_ == -1) |
104 selected_index_ = 0; | 105 selected_index_ = 0; |
105 | 106 |
106 int new_index = selected_index_; | 107 int new_index = selected_index_; |
107 switch (key_event.key_code()) { | 108 switch (key_event.key_code()) { |
108 // Move to the next item if any. | 109 // Move to the next item if any. |
(...skipping 26 matching lines...) Expand all Loading... |
135 | 136 |
136 if (new_index != selected_index_) { | 137 if (new_index != selected_index_) { |
137 selected_index_ = new_index; | 138 selected_index_ = new_index; |
138 combobox_->SelectionChanged(); | 139 combobox_->SelectionChanged(); |
139 SchedulePaint(); | 140 SchedulePaint(); |
140 } | 141 } |
141 | 142 |
142 return true; | 143 return true; |
143 } | 144 } |
144 | 145 |
145 bool NativeComboboxViews::OnKeyReleased(const views::KeyEvent& key_event) { | 146 bool NativeComboboxViews::OnKeyReleased(const ui::KeyEvent& key_event) { |
146 return true; | 147 return true; |
147 } | 148 } |
148 | 149 |
149 void NativeComboboxViews::OnPaint(gfx::Canvas* canvas) { | 150 void NativeComboboxViews::OnPaint(gfx::Canvas* canvas) { |
150 text_border_->set_has_focus(combobox_->HasFocus()); | 151 text_border_->set_has_focus(combobox_->HasFocus()); |
151 OnPaintBackground(canvas); | 152 OnPaintBackground(canvas); |
152 PaintText(canvas); | 153 PaintText(canvas); |
153 OnPaintBorder(canvas); | 154 OnPaintBorder(canvas); |
154 } | 155 } |
155 | 156 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 } | 220 } |
220 | 221 |
221 View* NativeComboboxViews::GetView() { | 222 View* NativeComboboxViews::GetView() { |
222 return this; | 223 return this; |
223 } | 224 } |
224 | 225 |
225 void NativeComboboxViews::SetFocus() { | 226 void NativeComboboxViews::SetFocus() { |
226 text_border_->set_has_focus(true); | 227 text_border_->set_has_focus(true); |
227 } | 228 } |
228 | 229 |
229 bool NativeComboboxViews::HandleKeyPressed(const KeyEvent& e) { | 230 bool NativeComboboxViews::HandleKeyPressed(const ui::KeyEvent& e) { |
230 return OnKeyPressed(e); | 231 return OnKeyPressed(e); |
231 } | 232 } |
232 | 233 |
233 bool NativeComboboxViews::HandleKeyReleased(const KeyEvent& e) { | 234 bool NativeComboboxViews::HandleKeyReleased(const ui::KeyEvent& e) { |
234 return false; // crbug.com/127520 | 235 return false; // crbug.com/127520 |
235 } | 236 } |
236 | 237 |
237 void NativeComboboxViews::HandleFocus() { | 238 void NativeComboboxViews::HandleFocus() { |
238 SchedulePaint(); | 239 SchedulePaint(); |
239 } | 240 } |
240 | 241 |
241 void NativeComboboxViews::HandleBlur() { | 242 void NativeComboboxViews::HandleBlur() { |
242 } | 243 } |
243 | 244 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 | 358 |
358 #if defined(USE_AURA) | 359 #if defined(USE_AURA) |
359 // static | 360 // static |
360 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper( | 361 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper( |
361 Combobox* combobox) { | 362 Combobox* combobox) { |
362 return new NativeComboboxViews(combobox); | 363 return new NativeComboboxViews(combobox); |
363 } | 364 } |
364 #endif | 365 #endif |
365 | 366 |
366 } // namespace views | 367 } // namespace views |
OLD | NEW |