1 // Copyright (c) 2013 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_FOLDER_HEADER_VIEW_H_ 6 #define UI_APP_LIST_VIEWS_FOLDER_HEADER_VIEW_H_ 7 8 #include <string> 9 10 #include "ui/app_list/app_list_export.h" 11 #include "ui/app_list/app_list_item_observer.h" 12 #include "ui/views/controls/button/button.h" 13 #include "ui/views/controls/textfield/textfield_controller.h" 14 #include "ui/views/view.h" 15 16 namespace views { 17 class ImageButton; 18 } // namespace views 19 20 namespace app_list { 21 22 class AppListFolderItem; 23 class AppListFolderView; 24 class FolderHeaderViewDelegate; 25 26 namespace test { 27 class FolderHeaderViewTest; 28 } 29 30 // FolderHeaderView contains a back button and an editable folder name field. 31 class APP_LIST_EXPORT FolderHeaderView : public views::View, 32 public views::TextfieldController, 33 public views::ButtonListener, 34 public AppListItemObserver { 35 public: 36 explicit FolderHeaderView(FolderHeaderViewDelegate* delegate); 37 virtual ~FolderHeaderView(); 38 39 void SetFolderItem(AppListFolderItem* folder_item); 40 void UpdateFolderNameVisibility(bool visible); 41 void OnFolderItemRemoved(); 42 43 // Overridden from views::View: 44 virtual gfx::Size GetPreferredSize() const OVERRIDE; 45 46 private: 47 class FolderNameView; 48 friend class test::FolderHeaderViewTest; 49 50 // Updates UI. 51 void Update(); 52 53 // Updates the accessible name of the folder name control. 54 void UpdateFolderNameAccessibleName(); 55 56 // Gets and sets the folder name for test. 57 const base::string16& GetFolderNameForTest(); 58 void SetFolderNameForTest(const base::string16& name); 59 60 // Returns true if folder name is enabled, only for testing use. 61 bool IsFolderNameEnabledForTest() const; 62 63 // views::View overrides: 64 virtual void Layout() OVERRIDE; 65 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; 66 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 67 68 // views::TextfieldController overrides: 69 virtual void ContentsChanged(views::Textfield* sender, 70 const base::string16& new_contents) OVERRIDE; 71 72 // views::ButtonListener overrides: 73 virtual void ButtonPressed(views::Button* sender, 74 const ui::Event& event) OVERRIDE; 75 76 // AppListItemObserver overrides: 77 virtual void ItemNameChanged() OVERRIDE; 78 79 AppListFolderItem* folder_item_; // Not owned. 80 81 views::ImageButton* back_button_; // Owned by views hierarchy. 82 FolderNameView* folder_name_view_; // Owned by views hierarchy. 83 84 const base::string16 folder_name_placeholder_text_; 85 86 FolderHeaderViewDelegate* delegate_; 87 88 bool folder_name_visible_; 89 90 DISALLOW_COPY_AND_ASSIGN(FolderHeaderView); 91 }; 92 93 } // namespace app_list 94 95 #endif // UI_APP_LIST_VIEWS_FOLDER_HEADER_VIEW_H_ 96