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 "ui/gfx/font_list.h"
11 #include "ui/views/controls/button/button.h"
12 #include "ui/views/view.h"
21 class KeyboardDelegate
;
25 // Shows a keyboard the user can interact with. The delegate is notified any
26 // time the user presses a button.
27 class KeyboardView
: public views::View
, public views::ButtonListener
{
29 explicit KeyboardView(KeyboardDelegate
* delegate
);
30 virtual ~KeyboardView();
33 virtual void Layout() OVERRIDE
;
36 // The type of keys that are shown.
38 KEYBOARD_LAYOUT_ALPHA
,
40 // Uppercase characters.
41 KEYBOARD_LAYOUT_SHIFT
,
43 // Numeric characters.
44 KEYBOARD_LAYOUT_NUMERIC
,
47 int event_flags() const {
48 return (keyboard_layout_
== KEYBOARD_LAYOUT_SHIFT
) ?
49 ui::EF_SHIFT_DOWN
: ui::EF_NONE
;
52 void SetLayout(KeyboardLayout layout
);
54 // Lays out the buttons for the specified row.
55 void LayoutRow(const Row
& row
,
61 // Sets the rows to show.
62 void SetRows(const std::vector
<const Row
*>& rows
);
64 // Configures the button in a row.
65 void ConfigureButtonsInRow(int row_index
, const Row
& row
);
67 // Creates a new button.
68 views::View
* CreateButton();
70 // Returns the button corresponding to a key at the specified row/column.
71 views::LabelButton
* GetButton(int row
, int column
);
73 const Key
& GetKeyForButton(views::Button
* button
) const;
75 // Reset the fonts of all the buttons. |special_font| is used for the buttons
76 // that toggle the layout.
77 void ResetFonts(const gfx::FontList
& button_font
,
78 const gfx::FontList
& special_font
);
80 // views::ButtonListener:
81 virtual void ButtonPressed(views::Button
* sender
,
82 const ui::Event
& event
) OVERRIDE
;
84 KeyboardDelegate
* delegate_
;
86 // Maximium number of keys in a row. Determined from |rows_|.
89 KeyboardLayout keyboard_layout_
;
91 std::vector
<const Row
*> rows_
;
93 gfx::Size last_layout_size_
;
95 gfx::FontList button_font_
;
97 DISALLOW_COPY_AND_ASSIGN(KeyboardView
);
100 } // namespace examples
103 #endif // MOJO_EXAMPLES_KEYBOARD_KEYBOARD_VIEW_H_