Home | History | Annotate | Download | only in login
      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_CHROMEOS_LOGIN_TAKE_PHOTO_VIEW_H_
      6 #define CHROME_BROWSER_CHROMEOS_LOGIN_TAKE_PHOTO_VIEW_H_
      7 #pragma once
      8 
      9 #include "views/controls/button/button.h"
     10 #include "views/view.h"
     11 
     12 class SkBitmap;
     13 
     14 namespace views {
     15 class ImageButton;
     16 class Label;
     17 }  // namespace views
     18 
     19 namespace chromeos {
     20 
     21 class CameraImageView;
     22 
     23 // View used for showing video from camera and taking a snapshot from it.
     24 class TakePhotoView : public views::View,
     25                       public views::ButtonListener {
     26  public:
     27   class Delegate {
     28    public:
     29     virtual ~Delegate() {}
     30 
     31     // Called when the view has switched to capturing state.
     32     virtual void OnCapturingStarted() = 0;
     33 
     34     // Called when the view has switched from capturing state.
     35     virtual void OnCapturingStopped() = 0;
     36   };
     37 
     38   explicit TakePhotoView(Delegate* delegate);
     39   virtual ~TakePhotoView();
     40 
     41   // Initializes this view, its children and layout.
     42   void Init();
     43 
     44   // Updates image from camera.
     45   void UpdateVideoFrame(const SkBitmap& frame);
     46 
     47   // If in capturing mode, shows that camera is initializing by running
     48   // throbber above the picture. Disables snapshot button until frame is
     49   // received.
     50   void ShowCameraInitializing();
     51 
     52   // If in capturing mode, shows that camera is broken instead of video
     53   // frame and disables snapshot button until new frame is received.
     54   void ShowCameraError();
     55 
     56   // Returns the currently selected image.
     57   const SkBitmap& GetImage() const;
     58 
     59   // Sets the image indicating that the view is used only for image preview.
     60   void SetImage(SkBitmap* image);
     61 
     62   // Overridden from views::View:
     63   virtual gfx::Size GetPreferredSize();
     64 
     65   // Overridden from views::ButtonListener.
     66   virtual void ButtonPressed(views::Button* sender, const views::Event& event);
     67 
     68   bool is_capturing() const { return is_capturing_; }
     69 
     70   void set_show_title(bool show) { show_title_ = show; }
     71 
     72  private:
     73   // Initializes layout manager for this view.
     74   void InitLayout();
     75 
     76   views::Label* title_label_;
     77   views::ImageButton* snapshot_button_;
     78   CameraImageView* user_image_;
     79 
     80   // Indicates that we're in capturing mode. When |false|, new video frames
     81   // are not shown to user if received.
     82   bool is_capturing_;
     83 
     84   // Whether title label is present or not.
     85   bool show_title_;
     86 
     87   Delegate* delegate_;
     88 
     89   DISALLOW_COPY_AND_ASSIGN(TakePhotoView);
     90 };
     91 
     92 }  // namespace chromeos
     93 
     94 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_TAKE_PHOTO_VIEW_H_
     95