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_
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"
22 class KeyboardDelegate
;
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
{
30 explicit KeyboardView(KeyboardDelegate
* delegate
);
31 virtual ~KeyboardView();
34 virtual void Layout() override
;
37 // The type of keys that are shown.
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
,
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_|.
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
104 #endif // MOJO_EXAMPLES_KEYBOARD_KEYBOARD_VIEW_H_