| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef VIEWS_CONTROLS_COMBOBOX_NATIVE_COMBOBOX_VIEWS_H_ | |
| 6 #define VIEWS_CONTROLS_COMBOBOX_NATIVE_COMBOBOX_VIEWS_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "views/controls/combobox/native_combobox_wrapper.h" | |
| 10 #include "views/controls/menu/menu_delegate.h" | |
| 11 #include "views/view.h" | |
| 12 | |
| 13 namespace gfx { | |
| 14 class Canvas; | |
| 15 class Font; | |
| 16 } | |
| 17 | |
| 18 namespace views { | |
| 19 | |
| 20 class KeyEvent; | |
| 21 class FocusableBorder; | |
| 22 class MenuRunner; | |
| 23 | |
| 24 // A views/skia only implementation of NativeComboboxWrapper. | |
| 25 // No platform specific code is used. | |
| 26 class NativeComboboxViews : public views::View, | |
| 27 public NativeComboboxWrapper, | |
| 28 public views::MenuDelegate { | |
| 29 public: | |
| 30 explicit NativeComboboxViews(Combobox* parent); | |
| 31 virtual ~NativeComboboxViews(); | |
| 32 | |
| 33 // views::View overrides: | |
| 34 virtual bool OnMousePressed(const views::MouseEvent& mouse_event) OVERRIDE; | |
| 35 virtual bool OnMouseDragged(const views::MouseEvent& mouse_event) OVERRIDE; | |
| 36 virtual bool OnKeyPressed(const views::KeyEvent& key_event) OVERRIDE; | |
| 37 virtual bool OnKeyReleased(const views::KeyEvent& key_event) OVERRIDE; | |
| 38 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | |
| 39 virtual void OnFocus() OVERRIDE; | |
| 40 virtual void OnBlur() OVERRIDE; | |
| 41 | |
| 42 // NativeComboboxWrapper overrides: | |
| 43 virtual void UpdateFromModel() OVERRIDE; | |
| 44 virtual void UpdateSelectedItem() OVERRIDE; | |
| 45 virtual void UpdateEnabled() OVERRIDE; | |
| 46 virtual int GetSelectedItem() const OVERRIDE; | |
| 47 virtual bool IsDropdownOpen() const OVERRIDE; | |
| 48 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
| 49 virtual View* GetView() OVERRIDE; | |
| 50 virtual void SetFocus() OVERRIDE; | |
| 51 virtual bool HandleKeyPressed(const views::KeyEvent& event) OVERRIDE; | |
| 52 virtual bool HandleKeyReleased(const views::KeyEvent& event) OVERRIDE; | |
| 53 virtual void HandleFocus() OVERRIDE; | |
| 54 virtual void HandleBlur() OVERRIDE; | |
| 55 virtual gfx::NativeView GetTestingHandle() const OVERRIDE; | |
| 56 | |
| 57 // MenuDelegate overrides: | |
| 58 virtual bool IsItemChecked(int id) const OVERRIDE; | |
| 59 virtual bool IsCommandEnabled(int id) const OVERRIDE; | |
| 60 virtual void ExecuteCommand(int id) OVERRIDE; | |
| 61 virtual bool GetAccelerator(int id, ui::Accelerator* accelerator) OVERRIDE; | |
| 62 | |
| 63 // class name of internal | |
| 64 static const char kViewClassName[]; | |
| 65 | |
| 66 private: | |
| 67 // Returns the Combobox's font. | |
| 68 const gfx::Font& GetFont() const; | |
| 69 | |
| 70 // Draw an arrow | |
| 71 void DrawArrow(gfx::Canvas* canvas, | |
| 72 int tip_x, int tip_y, int shift_x, int shift_y) const; | |
| 73 | |
| 74 // Draw the selected value of the drop down list | |
| 75 void PaintText(gfx::Canvas* canvas); | |
| 76 | |
| 77 // Show the drop down list | |
| 78 void ShowDropDownMenu(); | |
| 79 | |
| 80 // The parent combobox, the owner of this object. | |
| 81 Combobox* combobox_; | |
| 82 | |
| 83 // The reference to the border class. The object is owned by View::border_. | |
| 84 FocusableBorder* text_border_; | |
| 85 | |
| 86 // Responsible for showing the context menu. | |
| 87 scoped_ptr<MenuRunner> dropdown_list_menu_runner_; | |
| 88 | |
| 89 // Is the drop down list showing | |
| 90 bool dropdown_open_; | |
| 91 | |
| 92 // Index in the model of the selected item: -1 => none | |
| 93 int selected_item_; | |
| 94 | |
| 95 // The maximum dimensions of the content in the dropdown | |
| 96 int content_width_; | |
| 97 int content_height_; | |
| 98 | |
| 99 DISALLOW_COPY_AND_ASSIGN(NativeComboboxViews); | |
| 100 }; | |
| 101 | |
| 102 } // namespace views | |
| 103 | |
| 104 #endif // VIEWS_CONTROLS_COMBOBOX_NATIVE_COMBOBOX_VIEWS_H_ | |
| OLD | NEW |