summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/login/take_photo_view.h
blob: 0bb87e9783070913bb5a65c6629d36f0532eb558 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_TAKE_PHOTO_VIEW_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_TAKE_PHOTO_VIEW_H_
#pragma once

#include "base/compiler_specific.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/view.h"

class PhotoCaptureObserver;
class SkBitmap;

namespace gfx {
class ImageSkia;
}

namespace views {
class ImageButton;
class Label;
}

namespace chromeos {

class CameraImageView;

// View used for showing video from camera and taking a snapshot from it.
class TakePhotoView : public views::View,
                      public views::ButtonListener {
 public:
  class Delegate {
   public:
    virtual ~Delegate() {}

    // Called when the view has switched to capturing state.
    virtual void OnCapturingStarted() = 0;

    // Called when the view has switched from capturing state.
    virtual void OnCapturingStopped() = 0;
  };

  explicit TakePhotoView(Delegate* delegate);
  virtual ~TakePhotoView();

  // Initializes this view, its children and layout.
  void Init(int image_width, int image_height);

  // Updates image from camera.
  void UpdateVideoFrame(const SkBitmap& frame);

  // If in capturing mode, shows that camera is initializing by running
  // throbber above the picture. Disables snapshot button until frame is
  // received.
  void ShowCameraInitializing();

  // If in capturing mode, shows that camera is broken instead of video
  // frame and disables snapshot button until new frame is received.
  void ShowCameraError();

  // Returns the currently selected image.
  const gfx::ImageSkia& GetImage() const;

  // Sets the image indicating that the view is used only for image preview.
  void SetImage(gfx::ImageSkia* image);

  // Captures the image, as if the button was pressed.
  void CaptureImage();

  // Overridden from views::View:
  virtual gfx::Size GetPreferredSize() OVERRIDE;

  // Overridden from views::ButtonListener.
  virtual void ButtonPressed(views::Button* sender,
                             const views::Event& event) OVERRIDE;

  bool is_capturing() const { return is_capturing_; }

  void set_show_title(bool show) { show_title_ = show; }

 private:
  // Initializes layout manager for this view.
  void InitLayout();

  // For automation purposes.
  friend class ::PhotoCaptureObserver;
  void FlipCapturingState();

  views::Label* title_label_;
  views::ImageButton* snapshot_button_;
  CameraImageView* user_image_;

  // Indicates that we're in capturing mode. When |false|, new video frames
  // are not shown to user if received.
  bool is_capturing_;

  // Whether title label is present or not.
  bool show_title_;

  Delegate* delegate_;

  DISALLOW_COPY_AND_ASSIGN(TakePhotoView);
};

}  // namespace chromeos

#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_TAKE_PHOTO_VIEW_H_