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_FIRST_RUN_TRY_CHROME_DIALOG_VIEW_H_ 6#define CHROME_BROWSER_FIRST_RUN_TRY_CHROME_DIALOG_VIEW_H_ 7#pragma once 8 9#include "base/basictypes.h" 10#include "base/compiler_specific.h" 11#include "views/controls/button/button.h" 12#include "views/controls/link.h" 13#include "ui/gfx/native_widget_types.h" 14 15class ProcessSingleton; 16 17namespace gfx { 18class Rect; 19} 20 21namespace views { 22class RadioButton; 23class Widget; 24} 25 26// This class displays a modal dialog using the views system. The dialog asks 27// the user to give chrome another try. This class only handles the UI so the 28// resulting actions are up to the caller. One version looks like this: 29// 30// +-----------------------------------------------+ 31// | |icon| You stopped using Google Chrome [x] | 32// | |icon| Would you like to: | 33// | [o] Give the new version a try | 34// | [ ] Uninstall Google Chrome | 35// | [ OK ] [Don't bug me] | 36// | | 37// | _why_am_I_seeing this?_ | 38// +-----------------------------------------------+ 39// 40class TryChromeDialogView : public views::ButtonListener, 41 public views::LinkController { 42 public: 43 enum Result { 44 TRY_CHROME, // Launch chrome right now. 45 NOT_NOW, // Don't launch chrome. Exit now. 46 UNINSTALL_CHROME, // Initiate chrome uninstall and exit. 47 DIALOG_ERROR, // An error occurred creating the dialog. 48 COUNT 49 }; 50 51 // Shows a modal dialog asking the user to give chrome another try. See 52 // above for the possible outcomes of the function. This is an experimental, 53 // non-localized dialog. 54 // |version| can be 0, 1 or 2 and selects what strings to present. 55 // |process_singleton| needs to be valid and it will be locked while 56 // the dialog is shown. 57 // Note that the dialog has no parent and it will position itself in a lower 58 // corner of the screen. The dialog does not steal focus and does not have an 59 // entry in the taskbar. 60 static Result Show(size_t version, ProcessSingleton* process_singleton); 61 62 private: 63 enum ButtonTags { 64 BT_NONE, 65 BT_CLOSE_BUTTON, 66 BT_OK_BUTTON, 67 }; 68 69 explicit TryChromeDialogView(size_t version); 70 virtual ~TryChromeDialogView(); 71 72 Result ShowModal(ProcessSingleton* process_singleton); 73 74 // Returns a screen rectangle that is fit to show the window. In particular 75 // it has the following properties: a) is visible and b) is attached to the 76 // bottom of the working area. For LTR machines it returns a left side 77 // rectangle and for RTL it returns a right side rectangle so that the dialog 78 // does not compete with the standar place of the start menu. 79 gfx::Rect ComputeWindowPosition(int width, int height, bool is_RTL); 80 81 // Create a windows region that looks like a toast of width |w| and height 82 // |h|. This is best effort, so we don't care much if the operation fails. 83 void SetToastRegion(gfx::NativeWindow window, int w, int h); 84 85 // views::ButtonListener: 86 // We have two buttons and according to what the user clicked we set |result_| 87 // and we should always close and end the modal loop. 88 virtual void ButtonPressed(views::Button* sender, 89 const views::Event& event) OVERRIDE; 90 91 // views::LinkController: 92 // If the user selects the link we need to fire off the default browser that 93 // by some convoluted logic should not be chrome. 94 virtual void LinkActivated(views::Link* source, int event_flags) OVERRIDE; 95 96 // Controls which version of the text to use. 97 size_t version_; 98 99 // We don't own any of these pointers. The |popup_| owns itself and owns the 100 // other views. 101 views::Widget* popup_; 102 views::RadioButton* try_chrome_; 103 views::RadioButton* kill_chrome_; 104 Result result_; 105 106 DISALLOW_COPY_AND_ASSIGN(TryChromeDialogView); 107}; 108 109#endif // CHROME_BROWSER_FIRST_RUN_TRY_CHROME_DIALOG_VIEW_H_ 110