first_run_search_engine_view.h revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
1// Copyright (c) 2010 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_model_observer.h" 12#include "ui/gfx/size.h" 13#include "views/controls/button/native_button.h" 14#include "views/view.h" 15#include "views/window/window_delegate.h" 16 17namespace views { 18class ButtonListener; 19class ImageView; 20class Label; 21class Separator; 22class Window; 23} 24 25class Profile; 26class TemplateURL; 27class TemplateURLModel; 28 29// This class holds the logo and TemplateURL for a search engine and serves 30// as its button in the search engine selection view. 31class SearchEngineChoice : public views::NativeButton { 32 public: 33 // |listener| is the FirstRunView that waits for the search engine selection 34 // to complete; |search_engine| holds the data for the particular search 35 // engine this button represents; |use_small_logos| is true if we're 36 // displaying more than three choices. 37 SearchEngineChoice(views::ButtonListener* listener, 38 const TemplateURL* search_engine, 39 bool use_small_logos); 40 41 virtual ~SearchEngineChoice() {} 42 43 // These methods return data about the logo or text view associated 44 // with this search engine choice. 45 views::View* GetView() { return choice_view_; } 46 int GetChoiceViewWidth(); 47 int GetChoiceViewHeight(); 48 49 // Set the bounds for the search engine choice view; called in the 50 // Layout method, when we know what the new bounds should be. 51 void SetChoiceViewBounds(int x, int y, int width, int height); 52 53 // Accessor for the search engine data this button represents. 54 const TemplateURL* GetSearchEngine() { return search_engine_; } 55 56 // Used for UX testing. 57 void set_slot(int slot) { slot_ = slot; } 58 int slot() const { return slot_; } 59 60 private: 61 // Either an ImageView of a logo, or a Label with text. Owned by 62 // FirstRunSearchEngineView. 63 views::View* choice_view_; 64 65 // True if choice_view_ is holding an ImageView. 66 bool is_image_label_; 67 68 // Data for the search engine held here. 69 const TemplateURL* search_engine_; 70 71 // Used for UX testing. Gives slot in which search engine was shown. 72 int slot_; 73 74 DISALLOW_COPY_AND_ASSIGN(SearchEngineChoice); 75}; 76 77// This class displays a large search engine choice dialog view during 78// initial first run import. 79class FirstRunSearchEngineView 80 : public views::View, 81 public views::ButtonListener, 82 public views::WindowDelegate, 83 public TemplateURLModelObserver { 84 public: 85 // |profile| allows us to get the set of imported search engines. 86 // |randomize| is true if logos are to be displayed in random order. 87 FirstRunSearchEngineView(Profile* profile, bool randomize); 88 89 virtual ~FirstRunSearchEngineView(); 90 91 // Overridden from views::View: 92 virtual gfx::Size GetPreferredSize(); 93 virtual void Layout(); 94 virtual AccessibilityTypes::Role GetAccessibleRole(); 95 96 // Overridden from views::WindowDelegate: 97 virtual std::wstring GetWindowTitle() const; 98 views::View* GetContentsView() { return this; } 99 bool CanResize() const { return false; } 100 bool CanMaximize() const { return false; } 101 bool IsAlwaysOnTop() const { return true; } 102 bool HasAlwaysOnTopMenu() const { return false; } 103 104 // Overridden from views::ButtonListener: 105 virtual void ButtonPressed(views::Button* sender, const views::Event& event); 106 107 // Override from View so we can draw the gray background at dialog top. 108 virtual void Paint(gfx::Canvas* canvas); 109 110 // Overridden from TemplateURLModelObserver. When the search engines have 111 // loaded from the profile, we can populate the logos in the dialog box 112 // to present to the user. 113 virtual void OnTemplateURLModelChanged(); 114 115 private: 116 // Initializes the labels and controls in the view. 117 void SetupControls(); 118 119 // Owned by the profile_. 120 TemplateURLModel* search_engines_model_; 121 122 // One for each search engine choice offered, either three or four. 123 std::vector<SearchEngineChoice*> search_engine_choices_; 124 125 // If logos are to be displayed in random order. Used for UX testing. 126 bool randomize_; 127 128 // The profile associated with this import process. 129 Profile* profile_; 130 131 bool text_direction_is_rtl_; 132 133 // Image of browser search box with grey background and bubble arrow. 134 views::ImageView* background_image_; 135 136 // UI elements: 137 views::Label* title_label_; 138 views::Label* text_label_; 139 140 DISALLOW_COPY_AND_ASSIGN(FirstRunSearchEngineView); 141}; 142 143#endif // CHROME_BROWSER_UI_VIEWS_FIRST_RUN_SEARCH_ENGINE_VIEW_H_ 144 145