| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_FIRST_RUN_SEARCH_ENGINE_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_FIRST_RUN_SEARCH_ENGINE_VIEW_H_ |
| 6 #define 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 | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "chrome/browser/search_engines/template_url_service_observer.h" | 11 #include "chrome/browser/search_engines/template_url_service_observer.h" |
| 12 #include "ui/gfx/size.h" | 12 #include "ui/gfx/size.h" |
| 13 #include "ui/views/controls/button/text_button.h" | 13 #include "ui/views/controls/button/text_button.h" |
| 14 #include "ui/views/view.h" | 14 #include "ui/views/view.h" |
| 15 #include "ui/views/widget/widget_delegate.h" | 15 #include "ui/views/widget/widget_delegate.h" |
| 16 #include "ui/views/window/client_view.h" | |
| 17 | 16 |
| 18 class Profile; | 17 class Profile; |
| 19 class TemplateURL; | 18 class TemplateURL; |
| 20 class TemplateURLService; | 19 class TemplateURLService; |
| 21 class ThemeService; | 20 class ThemeService; |
| 22 | 21 |
| 23 namespace views { | 22 namespace views { |
| 24 class ImageView; | 23 class ImageView; |
| 25 class Label; | 24 class Label; |
| 26 } | 25 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 const TemplateURL* search_engine_; | 67 const TemplateURL* search_engine_; |
| 69 | 68 |
| 70 // Used for UX testing. Gives slot in which search engine was shown. | 69 // Used for UX testing. Gives slot in which search engine was shown. |
| 71 int slot_; | 70 int slot_; |
| 72 | 71 |
| 73 DISALLOW_COPY_AND_ASSIGN(SearchEngineChoice); | 72 DISALLOW_COPY_AND_ASSIGN(SearchEngineChoice); |
| 74 }; | 73 }; |
| 75 | 74 |
| 76 // This class displays a large search engine choice dialog view during | 75 // This class displays a large search engine choice dialog view during |
| 77 // initial first run import. | 76 // initial first run import. |
| 78 class FirstRunSearchEngineView : public views::ClientView, | 77 class FirstRunSearchEngineView : public views::WidgetDelegateView, |
| 79 public views::WidgetDelegate, | |
| 80 public views::ButtonListener, | 78 public views::ButtonListener, |
| 81 public TemplateURLServiceObserver { | 79 public TemplateURLServiceObserver { |
| 82 public: | 80 public: |
| 83 // |profile| allows us to get the set of imported search engines. | 81 // |profile| allows us to get the set of imported search engines. |
| 84 // |randomize| is true if logos are to be displayed in random order. | 82 // |randomize| is true if logos are to be displayed in random order. |
| 85 FirstRunSearchEngineView(Profile* profile, bool randomize); | 83 FirstRunSearchEngineView(Profile* profile, bool randomize); |
| 86 | 84 |
| 87 virtual ~FirstRunSearchEngineView(); | 85 virtual ~FirstRunSearchEngineView(); |
| 88 | 86 |
| 89 // Overridden from views::WidgetDelegate: | 87 // Overridden from views::WidgetDelegateView: |
| 90 virtual string16 GetWindowTitle() const OVERRIDE; | 88 virtual string16 GetWindowTitle() const OVERRIDE; |
| 91 virtual views::View* GetContentsView() OVERRIDE; | 89 virtual views::View* GetContentsView() OVERRIDE { return this; } |
| 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 | 90 |
| 100 // Overridden from views::ButtonListener: | 91 // Overridden from views::ButtonListener: |
| 101 virtual void ButtonPressed(views::Button* sender, | 92 virtual void ButtonPressed(views::Button* sender, |
| 102 const views::Event& event) OVERRIDE; | 93 const views::Event& event) OVERRIDE; |
| 103 | 94 |
| 104 // Overridden from views::View: | 95 // Overridden from views::View: |
| 105 virtual gfx::Size GetPreferredSize() OVERRIDE; | 96 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 106 virtual void Layout() OVERRIDE; | 97 virtual void Layout() OVERRIDE; |
| 107 virtual void ViewHierarchyChanged(bool is_add, | 98 virtual void ViewHierarchyChanged(bool is_add, |
| 108 View* parent, | 99 View* parent, |
| 109 View* child) OVERRIDE; | 100 View* child) OVERRIDE; |
| 110 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 101 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
| 111 | 102 |
| 112 // Override from views::View so we can draw the gray background at dialog top. | 103 // Override from views::View so we can draw the gray background at dialog top. |
| 113 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 104 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
| 114 | 105 |
| 115 // Overridden from TemplateURLServiceObserver. When the search engines have | 106 // Overridden from TemplateURLServiceObserver. When the search engines have |
| 116 // loaded from the profile, we can populate the logos in the dialog box | 107 // loaded from the profile, we can populate the logos in the dialog box |
| 117 // to present to the user. | 108 // to present to the user. |
| 118 virtual void OnTemplateURLServiceChanged() OVERRIDE; | 109 virtual void OnTemplateURLServiceChanged() OVERRIDE; |
| 119 | 110 |
| 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: | 111 private: |
| 127 // Once the TemplateURLService has loaded and we're in a View hierarchy, it's | 112 // Once the TemplateURLService has loaded and we're in a View hierarchy, it's |
| 128 // OK to add the search engines from the TemplateURLService. | 113 // OK to add the search engines from the TemplateURLService. |
| 129 void AddSearchEnginesIfPossible(); | 114 void AddSearchEnginesIfPossible(); |
| 130 | 115 |
| 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. | 116 // One for each search engine choice offered, either three or four. |
| 135 std::vector<SearchEngineChoice*> search_engine_choices_; | 117 std::vector<SearchEngineChoice*> search_engine_choices_; |
| 136 | 118 |
| 137 // If logos are to be displayed in random order. Used for UX testing. | 119 // If logos are to be displayed in random order. Used for UX testing. |
| 138 bool randomize_; | 120 bool randomize_; |
| 139 | 121 |
| 140 // Services associated with the current profile. | 122 // Services associated with the current profile. |
| 141 TemplateURLService* template_url_service_; | 123 TemplateURLService* template_url_service_; |
| 142 ThemeService* theme_service_; | 124 ThemeService* theme_service_; |
| 143 | 125 |
| 144 bool text_direction_is_rtl_; | 126 bool text_direction_is_rtl_; |
| 145 | 127 |
| 128 bool template_url_service_loaded_; |
| 146 bool added_to_view_hierarchy_; | 129 bool added_to_view_hierarchy_; |
| 147 | 130 |
| 148 // Image of browser search box with grey background and bubble arrow. | 131 // Image of browser search box with grey background and bubble arrow. |
| 149 views::ImageView* background_image_; | 132 views::ImageView* background_image_; |
| 150 | 133 |
| 151 // UI elements: | 134 // UI elements: |
| 152 views::Label* title_label_; | 135 views::Label* title_label_; |
| 153 views::Label* text_label_; | 136 views::Label* text_label_; |
| 154 | 137 |
| 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); | 138 DISALLOW_COPY_AND_ASSIGN(FirstRunSearchEngineView); |
| 172 }; | 139 }; |
| 173 | 140 |
| 174 #endif // CHROME_BROWSER_UI_VIEWS_FIRST_RUN_SEARCH_ENGINE_VIEW_H_ | 141 #endif // CHROME_BROWSER_UI_VIEWS_FIRST_RUN_SEARCH_ENGINE_VIEW_H_ |
| OLD | NEW |