Home | History | Annotate | Download | only in autofill
      1 // Copyright 2013 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_AUTOFILL_AUTOCHECKOUT_BUBBLE_CONTROLLER_H_
      6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOCHECKOUT_BUBBLE_CONTROLLER_H_
      7 
      8 #include "base/callback.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "base/strings/string16.h"
     11 #include "components/autofill/core/browser/autocheckout_bubble_state.h"
     12 #include "ui/gfx/native_widget_types.h"
     13 #include "ui/gfx/rect.h"
     14 
     15 namespace gfx {
     16 class Image;
     17 }
     18 
     19 namespace autofill {
     20 
     21 class AutofillMetrics;
     22 
     23 // The controller for the Autocheckout bubble UI. Implements a platform
     24 // agnostic way to interact with the bubble, in addition to being a place
     25 // for shared code such as display strings and tracking.
     26 class AutocheckoutBubbleController {
     27  public:
     28   // |anchor_rect| is the anchor for the bubble UI. It is the bounds of an
     29   // input element in viewport space. |native_window| is the parent view of the
     30   // bubble. |is_google_user| is whether or not the user is logged into or has
     31   // been logged into accounts.google.com. |callback| is invoked if the bubble
     32   // is accepted. It brings up the requestAutocomplete dialog to collect user
     33   // input for Autocheckout.
     34   AutocheckoutBubbleController(
     35       const gfx::RectF& anchor_rect,
     36       const gfx::NativeWindow& native_window,
     37       bool  is_google_user,
     38       const base::Callback<void(AutocheckoutBubbleState)>& callback);
     39   ~AutocheckoutBubbleController();
     40 
     41   static base::string16 AcceptText();
     42   static base::string16 CancelText();
     43   base::string16 PromptText();
     44 
     45   void BubbleAccepted();
     46   void BubbleCanceled();
     47   void BubbleCreated() const;
     48   void BubbleDestroyed() const;
     49 
     50   gfx::Image NormalImage();
     51   gfx::Image HoverImage();
     52   gfx::Image PressedImage();
     53 
     54   const gfx::Rect& anchor_rect() const { return anchor_rect_; }
     55 
     56   const gfx::NativeWindow& native_window() const {
     57     return native_window_;
     58   }
     59 
     60  protected:
     61   void set_metric_logger(AutofillMetrics* metric_logger);
     62 
     63   const AutofillMetrics* metric_logger() const {
     64     return metric_logger_.get();
     65   }
     66 
     67  private:
     68   // |anchor_rect_| is the anchor for the bubble UI. It is the bounds of an
     69   // input element in viewport space.
     70   gfx::Rect anchor_rect_;
     71 
     72   // |native_window| is the parent window of the bubble.
     73   gfx::NativeWindow native_window_;
     74 
     75   // Whether or not the user has or is logged into accounts.google.com. Used to
     76   // vary the messaging on the bubble.
     77   bool is_google_user_;
     78 
     79   // |callback_| is invoked if the bubble is accepted.
     80   base::Callback<void(AutocheckoutBubbleState)> callback_;
     81 
     82   // For logging UMA metrics. Overridden by metrics tests.
     83   scoped_ptr<const AutofillMetrics> metric_logger_;
     84 
     85   // Whether or not the user interacted with the bubble.
     86   bool had_user_interaction_;
     87 
     88   DISALLOW_COPY_AND_ASSIGN(AutocheckoutBubbleController);
     89 };
     90 
     91 }  // namespace autofill
     92 
     93 #endif  // CHROME_BROWSER_UI_AUTOFILL_AUTOCHECKOUT_BUBBLE_CONTROLLER_H_
     94 
     95