| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 CHROME_BROWSER_UI_VIEWS_FIRST_RUN_SEARCH_ENGINE_VIEW_H_ | |
| 6 #define CHROME_BROWSER_UI_VIEWS_FIRST_RUN_SEARCH_ENGINE_VIEW_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "chrome/browser/search_engines/template_url_service_observer.h" | |
| 12 #include "ui/gfx/size.h" | |
| 13 #include "ui/views/controls/button/text_button.h" | |
| 14 #include "ui/views/view.h" | |
| 15 #include "ui/views/widget/widget_delegate.h" | |
| 16 #include "ui/views/window/client_view.h" | |
| 17 | |
| 18 class Profile; | |
| 19 class TemplateURL; | |
| 20 class TemplateURLService; | |
| 21 class ThemeService; | |
| 22 | |
| 23 namespace views { | |
| 24 class ImageView; | |
| 25 class Label; | |
| 26 } | |
| 27 | |
| 28 // This class holds the logo and TemplateURL for a search engine and serves | |
| 29 // as its button in the search engine selection view. | |
| 30 class SearchEngineChoice : public views::NativeTextButton { | |
| 31 public: | |
| 32 // |listener| is the FirstRunView that waits for the search engine selection | |
| 33 // to complete; |search_engine| holds the data for the particular search | |
| 34 // engine this button represents; |use_small_logos| is true if we're | |
| 35 // displaying more than three choices. | |
| 36 SearchEngineChoice(views::ButtonListener* listener, | |
| 37 const TemplateURL* search_engine, | |
| 38 bool use_small_logos); | |
| 39 | |
| 40 virtual ~SearchEngineChoice() {} | |
| 41 | |
| 42 // These methods return data about the logo or text view associated | |
| 43 // with this search engine choice. | |
| 44 views::View* GetView() { return choice_view_; } | |
| 45 int GetChoiceViewWidth(); | |
| 46 int GetChoiceViewHeight(); | |
| 47 | |
| 48 // Set the bounds for the search engine choice view; called in the | |
| 49 // Layout method, when we know what the new bounds should be. | |
| 50 void SetChoiceViewBounds(int x, int y, int width, int height); | |
| 51 | |
| 52 // Accessor for the search engine data this button represents. | |
| 53 const TemplateURL* GetSearchEngine() { return search_engine_; } | |
| 54 | |
| 55 // Used for UX testing. | |
| 56 void set_slot(int slot) { slot_ = slot; } | |
| 57 int slot() const { return slot_; } | |
| 58 | |
| 59 private: | |
| 60 // Either an ImageView of a logo, or a Label with text. Owned by | |
| 61 // FirstRunSearchEngineView. | |
| 62 views::View* choice_view_; | |
| 63 | |
| 64 // True if choice_view_ is holding an ImageView. | |
| 65 bool is_image_label_; | |
| 66 | |
| 67 // Data for the search engine held here. | |
| 68 const TemplateURL* search_engine_; | |
| 69 | |
| 70 // Used for UX testing. Gives slot in which search engine was shown. | |
| 71 int slot_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(SearchEngineChoice); | |
| 74 }; | |
| 75 | |
| 76 // This class displays a large search engine choice dialog view during | |
| 77 // initial first run import. | |
| 78 class FirstRunSearchEngineView : public views::ClientView, | |
| 79 public views::WidgetDelegate, | |
| 80 public views::ButtonListener, | |
| 81 public TemplateURLServiceObserver { | |
| 82 public: | |
| 83 // |profile| allows us to get the set of imported search engines. | |
| 84 // |randomize| is true if logos are to be displayed in random order. | |
| 85 FirstRunSearchEngineView(Profile* profile, bool randomize); | |
| 86 | |
| 87 virtual ~FirstRunSearchEngineView(); | |
| 88 | |
| 89 // Overridden from views::WidgetDelegate: | |
| 90 virtual string16 GetWindowTitle() const OVERRIDE; | |
| 91 virtual views::View* GetContentsView() OVERRIDE; | |
| 92 virtual views::ClientView* CreateClientView(views::Widget* widget) OVERRIDE; | |
| 93 virtual void WindowClosing() OVERRIDE; | |
| 94 virtual views::Widget* GetWidget() OVERRIDE; | |
| 95 virtual const views::Widget* GetWidget() const OVERRIDE; | |
| 96 | |
| 97 // Overridden from views::ClientView: | |
| 98 virtual bool CanClose() OVERRIDE; | |
| 99 | |
| 100 // Overridden from views::ButtonListener: | |
| 101 virtual void ButtonPressed(views::Button* sender, | |
| 102 const views::Event& event) OVERRIDE; | |
| 103 | |
| 104 // Overridden from views::View: | |
| 105 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
| 106 virtual void Layout() OVERRIDE; | |
| 107 virtual void ViewHierarchyChanged(bool is_add, | |
| 108 View* parent, | |
| 109 View* child) OVERRIDE; | |
| 110 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | |
| 111 | |
| 112 // Override from views::View so we can draw the gray background at dialog top. | |
| 113 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | |
| 114 | |
| 115 // Overridden from TemplateURLServiceObserver. When the search engines have | |
| 116 // loaded from the profile, we can populate the logos in the dialog box | |
| 117 // to present to the user. | |
| 118 virtual void OnTemplateURLServiceChanged() OVERRIDE; | |
| 119 | |
| 120 #if defined(UNIT_TEST) | |
| 121 void set_quit_on_closing(bool quit_on_closing) { | |
| 122 quit_on_closing_ = quit_on_closing; | |
| 123 } | |
| 124 #endif | |
| 125 | |
| 126 private: | |
| 127 // Once the TemplateURLService has loaded and we're in a View hierarchy, it's | |
| 128 // OK to add the search engines from the TemplateURLService. | |
| 129 void AddSearchEnginesIfPossible(); | |
| 130 | |
| 131 // Sets the default search engine to the one represented by |choice|. | |
| 132 void ChooseSearchEngine(SearchEngineChoice* choice); | |
| 133 | |
| 134 // One for each search engine choice offered, either three or four. | |
| 135 std::vector<SearchEngineChoice*> search_engine_choices_; | |
| 136 | |
| 137 // If logos are to be displayed in random order. Used for UX testing. | |
| 138 bool randomize_; | |
| 139 | |
| 140 // Services associated with the current profile. | |
| 141 TemplateURLService* template_url_service_; | |
| 142 ThemeService* theme_service_; | |
| 143 | |
| 144 bool text_direction_is_rtl_; | |
| 145 | |
| 146 bool added_to_view_hierarchy_; | |
| 147 | |
| 148 // Image of browser search box with grey background and bubble arrow. | |
| 149 views::ImageView* background_image_; | |
| 150 | |
| 151 // UI elements: | |
| 152 views::Label* title_label_; | |
| 153 views::Label* text_label_; | |
| 154 | |
| 155 // True when the user has chosen a particular search engine. Defaults to | |
| 156 // false. When the user closes the window without choosing a search engine, | |
| 157 // the engine specified by |fallback_choice_| is chosen. | |
| 158 bool user_chosen_engine_; | |
| 159 | |
| 160 // The engine to choose when the user closes the window without explicitly | |
| 161 // making a selection. Because of randomization functionality, we cannot | |
| 162 // reliably deduce this from slot order, so this value is saved prior to | |
| 163 // randomization. | |
| 164 SearchEngineChoice* fallback_choice_; | |
| 165 | |
| 166 // Defaults to true. Indicates that the current message loop should be quit | |
| 167 // when the window is closed. This is false in tests when this dialog does not | |
| 168 // spin its own message loop. | |
| 169 bool quit_on_closing_; | |
| 170 | |
| 171 DISALLOW_COPY_AND_ASSIGN(FirstRunSearchEngineView); | |
| 172 }; | |
| 173 | |
| 174 #endif // CHROME_BROWSER_UI_VIEWS_FIRST_RUN_SEARCH_ENGINE_VIEW_H_ | |
| OLD | NEW |