Home | History | Annotate | Download | only in views
      1 // Copyright (c) 2012 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 UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_
      6 #define UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_
      7 
      8 #include <string>
      9 
     10 #include "ui/app_list/search_box_model_observer.h"
     11 #include "ui/app_list/speech_ui_model_observer.h"
     12 #include "ui/views/controls/button/image_button.h"
     13 #include "ui/views/controls/button/menu_button_listener.h"
     14 #include "ui/views/controls/textfield/textfield_controller.h"
     15 #include "ui/views/view.h"
     16 
     17 namespace views {
     18 class ImageView;
     19 class MenuButton;
     20 class Textfield;
     21 }  // namespace views
     22 
     23 namespace app_list {
     24 
     25 class AppListMenuViews;
     26 class AppListModel;
     27 class AppListViewDelegate;
     28 class SearchBoxModel;
     29 class SearchBoxViewDelegate;
     30 
     31 // SearchBoxView consists of an icon and a Textfield. SearchBoxModel is its data
     32 // model that controls what icon to display, what placeholder text to use for
     33 // Textfield. The text and selection model part could be set to change the
     34 // contents and selection model of the Textfield.
     35 class APP_LIST_EXPORT SearchBoxView : public views::View,
     36                                       public views::TextfieldController,
     37                                       public views::ButtonListener,
     38                                       public views::MenuButtonListener,
     39                                       public SearchBoxModelObserver,
     40                                       public SpeechUIModelObserver {
     41  public:
     42   SearchBoxView(SearchBoxViewDelegate* delegate,
     43                 AppListViewDelegate* view_delegate);
     44   virtual ~SearchBoxView();
     45 
     46   void ModelChanged();
     47   bool HasSearch() const;
     48   void ClearSearch();
     49   void InvalidateMenu();
     50 
     51   views::Textfield* search_box() { return search_box_; }
     52 
     53   void set_contents_view(views::View* contents_view) {
     54     contents_view_ = contents_view;
     55   }
     56 
     57   // Overridden from views::View:
     58   virtual gfx::Size GetPreferredSize() const OVERRIDE;
     59   virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE;
     60 
     61  private:
     62   // Updates model text and selection model with current Textfield info.
     63   void UpdateModel();
     64 
     65   // Fires query change notification.
     66   void NotifyQueryChanged();
     67 
     68   // Overridden from views::TextfieldController:
     69   virtual void ContentsChanged(views::Textfield* sender,
     70                                const base::string16& new_contents) OVERRIDE;
     71   virtual bool HandleKeyEvent(views::Textfield* sender,
     72                               const ui::KeyEvent& key_event) OVERRIDE;
     73 
     74   // Overridden from views::ButtonListener:
     75   virtual void ButtonPressed(views::Button* sender,
     76                              const ui::Event& event) OVERRIDE;
     77 
     78   // Overridden from views::MenuButtonListener:
     79   virtual void OnMenuButtonClicked(View* source,
     80                                    const gfx::Point& point) OVERRIDE;
     81 
     82   // Overridden from SearchBoxModelObserver:
     83   virtual void IconChanged() OVERRIDE;
     84   virtual void SpeechRecognitionButtonPropChanged() OVERRIDE;
     85   virtual void HintTextChanged() OVERRIDE;
     86   virtual void SelectionModelChanged() OVERRIDE;
     87   virtual void TextChanged() OVERRIDE;
     88 
     89   // Overridden from SpeechUIModelObserver:
     90   virtual void OnSpeechRecognitionStateChanged(
     91       SpeechRecognitionState new_state) OVERRIDE;
     92 
     93   SearchBoxViewDelegate* delegate_;  // Not owned.
     94   AppListViewDelegate* view_delegate_;  // Not owned.
     95   AppListModel* model_;  // Owned by the profile-keyed service.
     96 
     97   scoped_ptr<AppListMenuViews> menu_;
     98 
     99   views::ImageView* icon_view_;  // Owned by views hierarchy.
    100   views::ImageButton* speech_button_;  // Owned by views hierarchy.
    101   views::MenuButton* menu_button_;  // Owned by views hierarchy.
    102   views::Textfield* search_box_;  // Owned by views hierarchy.
    103   views::View* contents_view_;  // Owned by views hierarchy.
    104 
    105   DISALLOW_COPY_AND_ASSIGN(SearchBoxView);
    106 };
    107 
    108 }  // namespace app_list
    109 
    110 #endif  // UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_
    111