OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 MOJO_EXAMPLES_KEYBOARD_KEYBOARD_VIEW_H_ | |
6 #define MOJO_EXAMPLES_KEYBOARD_KEYBOARD_VIEW_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/macros.h" | |
11 #include "ui/gfx/font_list.h" | |
12 #include "ui/views/controls/button/button.h" | |
13 #include "ui/views/view.h" | |
14 | |
15 namespace views { | |
16 class LabelButton; | |
17 } | |
18 | |
19 namespace mojo { | |
20 namespace examples { | |
21 | |
22 class KeyboardDelegate; | |
23 struct Key; | |
24 struct Row; | |
25 | |
26 // Shows a keyboard the user can interact with. The delegate is notified any | |
27 // time the user presses a button. | |
28 class KeyboardView : public views::View, public views::ButtonListener { | |
29 public: | |
30 explicit KeyboardView(KeyboardDelegate* delegate); | |
31 virtual ~KeyboardView(); | |
32 | |
33 // views::View: | |
34 virtual void Layout() override; | |
35 | |
36 private: | |
37 // The type of keys that are shown. | |
38 enum KeyboardLayout { | |
39 KEYBOARD_LAYOUT_ALPHA, | |
40 | |
41 // Uppercase characters. | |
42 KEYBOARD_LAYOUT_SHIFT, | |
43 | |
44 // Numeric characters. | |
45 KEYBOARD_LAYOUT_NUMERIC, | |
46 }; | |
47 | |
48 int event_flags() const { | |
49 return (keyboard_layout_ == KEYBOARD_LAYOUT_SHIFT) ? | |
50 ui::EF_SHIFT_DOWN : ui::EF_NONE; | |
51 } | |
52 | |
53 void SetLayout(KeyboardLayout layout); | |
54 | |
55 // Lays out the buttons for the specified row. | |
56 void LayoutRow(const Row& row, | |
57 int row_index, | |
58 int initial_x, | |
59 int button_width, | |
60 int button_height); | |
61 | |
62 // Sets the rows to show. | |
63 void SetRows(const std::vector<const Row*>& rows); | |
64 | |
65 // Configures the button in a row. | |
66 void ConfigureButtonsInRow(int row_index, const Row& row); | |
67 | |
68 // Creates a new button. | |
69 views::View* CreateButton(); | |
70 | |
71 // Returns the button corresponding to a key at the specified row/column. | |
72 views::LabelButton* GetButton(int row, int column); | |
73 | |
74 const Key& GetKeyForButton(views::Button* button) const; | |
75 | |
76 // Reset the fonts of all the buttons. |special_font| is used for the buttons | |
77 // that toggle the layout. | |
78 void ResetFonts(const gfx::FontList& button_font, | |
79 const gfx::FontList& special_font); | |
80 | |
81 // views::ButtonListener: | |
82 virtual void ButtonPressed(views::Button* sender, | |
83 const ui::Event& event) override; | |
84 | |
85 KeyboardDelegate* delegate_; | |
86 | |
87 // Maximium number of keys in a row. Determined from |rows_|. | |
88 int max_keys_in_row_; | |
89 | |
90 KeyboardLayout keyboard_layout_; | |
91 | |
92 std::vector<const Row*> rows_; | |
93 | |
94 gfx::Size last_layout_size_; | |
95 | |
96 gfx::FontList button_font_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(KeyboardView); | |
99 }; | |
100 | |
101 } // namespace examples | |
102 } // namespace mojo | |
103 | |
104 #endif // MOJO_EXAMPLES_KEYBOARD_KEYBOARD_VIEW_H_ | |
OLD | NEW |