Home | History | Annotate | Download | only in views
      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 
     17 namespace views {
     18 class ButtonListener;
     19 class ImageView;
     20 class Label;
     21 class Separator;
     22 class Window;
     23 }
     24 
     25 class Profile;
     26 class TemplateURL;
     27 class 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.
     31 class 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.
     79 class 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   bool IsAlwaysOnTop() const { return true; }
     92   bool HasAlwaysOnTopMenu() const { return false; }
     93 
     94   // Overridden from views::View:
     95   virtual gfx::Size GetPreferredSize() OVERRIDE;
     96   virtual void Layout() OVERRIDE;
     97   virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
     98 
     99   // Overridden from views::WindowDelegate:
    100   virtual std::wstring GetWindowTitle() const OVERRIDE;
    101   views::View* GetContentsView() OVERRIDE { return this; }
    102   bool CanResize() const OVERRIDE{ return false; }
    103   bool CanMaximize() const OVERRIDE { return false; }
    104 
    105   // Overridden from views::ButtonListener:
    106   virtual void ButtonPressed(views::Button* sender, const views::Event& event)
    107       OVERRIDE;
    108 
    109   // Override from View so we can draw the gray background at dialog top.
    110   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
    111 
    112   // Overridden from TemplateURLModelObserver. When the search engines have
    113   // loaded from the profile, we can populate the logos in the dialog box
    114   // to present to the user.
    115   virtual void OnTemplateURLModelChanged() OVERRIDE;
    116 
    117  private:
    118   // Initializes the labels and controls in the view.
    119   void SetupControls();
    120 
    121   // Owned by the profile_.
    122   TemplateURLModel* search_engines_model_;
    123 
    124   // One for each search engine choice offered, either three or four.
    125   std::vector<SearchEngineChoice*> search_engine_choices_;
    126 
    127   // If logos are to be displayed in random order. Used for UX testing.
    128   bool randomize_;
    129 
    130   // The profile associated with this import process.
    131   Profile* profile_;
    132 
    133   bool text_direction_is_rtl_;
    134 
    135   // Image of browser search box with grey background and bubble arrow.
    136   views::ImageView* background_image_;
    137 
    138   // UI elements:
    139   views::Label* title_label_;
    140   views::Label* text_label_;
    141 
    142   DISALLOW_COPY_AND_ASSIGN(FirstRunSearchEngineView);
    143 };
    144 
    145 #endif  // CHROME_BROWSER_UI_VIEWS_FIRST_RUN_SEARCH_ENGINE_VIEW_H_
    146