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