mojo: Fix map of booleans for python bindings.
[chromium-blink-merge.git] / mojo / examples / keyboard / keyboard_view.h
blob4086a2dc7624de6748cc94793658ec6a4bc0bec5
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.
5 #ifndef MOJO_EXAMPLES_KEYBOARD_KEYBOARD_VIEW_H_
6 #define MOJO_EXAMPLES_KEYBOARD_KEYBOARD_VIEW_H_
8 #include <vector>
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"
15 namespace views {
16 class LabelButton;
19 namespace mojo {
20 namespace examples {
22 class KeyboardDelegate;
23 struct Key;
24 struct Row;
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();
33 // views::View:
34 virtual void Layout() override;
36 private:
37 // The type of keys that are shown.
38 enum KeyboardLayout {
39 KEYBOARD_LAYOUT_ALPHA,
41 // Uppercase characters.
42 KEYBOARD_LAYOUT_SHIFT,
44 // Numeric characters.
45 KEYBOARD_LAYOUT_NUMERIC,
48 int event_flags() const {
49 return (keyboard_layout_ == KEYBOARD_LAYOUT_SHIFT) ?
50 ui::EF_SHIFT_DOWN : ui::EF_NONE;
53 void SetLayout(KeyboardLayout layout);
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);
62 // Sets the rows to show.
63 void SetRows(const std::vector<const Row*>& rows);
65 // Configures the button in a row.
66 void ConfigureButtonsInRow(int row_index, const Row& row);
68 // Creates a new button.
69 views::View* CreateButton();
71 // Returns the button corresponding to a key at the specified row/column.
72 views::LabelButton* GetButton(int row, int column);
74 const Key& GetKeyForButton(views::Button* button) const;
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);
81 // views::ButtonListener:
82 virtual void ButtonPressed(views::Button* sender,
83 const ui::Event& event) override;
85 KeyboardDelegate* delegate_;
87 // Maximium number of keys in a row. Determined from |rows_|.
88 int max_keys_in_row_;
90 KeyboardLayout keyboard_layout_;
92 std::vector<const Row*> rows_;
94 gfx::Size last_layout_size_;
96 gfx::FontList button_font_;
98 DISALLOW_COPY_AND_ASSIGN(KeyboardView);
101 } // namespace examples
102 } // namespace mojo
104 #endif // MOJO_EXAMPLES_KEYBOARD_KEYBOARD_VIEW_H_