1// Copyright (c) 2012 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_COCOA_EXTENSIONS_EXTENSION_VIEW_MAC_H_
6#define CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_VIEW_MAC_H_
7
8#include "base/basictypes.h"
9#include "chrome/browser/extensions/extension_view.h"
10#include "third_party/skia/include/core/SkBitmap.h"
11#include "ui/gfx/native_widget_types.h"
12#include "ui/gfx/size.h"
13
14class Browser;
15class SkBitmap;
16
17namespace content {
18class RenderViewHost;
19}
20
21namespace extensions {
22class ExtensionHost;
23}
24
25// This class represents extension views. An extension view internally contains
26// a bridge to an extension process, which draws to the extension view's
27// native view object through IPC.
28class ExtensionViewMac : public extensions::ExtensionView {
29 public:
30  class Container {
31   public:
32    virtual ~Container() {}
33    virtual void OnExtensionSizeChanged(ExtensionViewMac* view,
34                                        const gfx::Size& new_size) {}
35    virtual void OnExtensionViewDidShow(ExtensionViewMac* view) {};
36  };
37
38  // The minimum/maximum dimensions of the popup.
39  // The minimum is just a little larger than the size of the button itself.
40  // The maximum is an arbitrary number that should be smaller than most
41  // screens.
42  static const CGFloat kMinWidth;
43  static const CGFloat kMinHeight;
44  static const CGFloat kMaxWidth;
45  static const CGFloat kMaxHeight;
46
47  ExtensionViewMac(extensions::ExtensionHost* extension_host, Browser* browser);
48  virtual ~ExtensionViewMac();
49
50  // Sets the container for this view.
51  void set_container(Container* container) { container_ = container; }
52
53  // Informs the view that its containing window's frame changed.
54  void WindowFrameChanged();
55
56  // extensions::ExtensionView:
57  virtual void Init() OVERRIDE;
58  virtual Browser* GetBrowser() OVERRIDE;
59  virtual gfx::NativeView GetNativeView() OVERRIDE;
60  virtual void ResizeDueToAutoResize(const gfx::Size& new_size) OVERRIDE;
61  virtual void RenderViewCreated() OVERRIDE;
62  virtual void HandleKeyboardEvent(
63      content::WebContents* source,
64      const content::NativeWebKeyboardEvent& event) OVERRIDE;
65  virtual void DidStopLoading() OVERRIDE;
66
67 private:
68  content::RenderViewHost* render_view_host() const;
69
70  void CreateWidgetHostView();
71
72  // We wait to show the ExtensionView until several things have loaded.
73  void ShowIfCompletelyLoaded();
74
75  Browser* browser_;  // weak
76
77  extensions::ExtensionHost* extension_host_;  // weak
78
79  // What we should set the preferred width to once the ExtensionView has
80  // loaded.
81  gfx::Size pending_preferred_size_;
82
83  Container* container_;
84
85  DISALLOW_COPY_AND_ASSIGN(ExtensionViewMac);
86};
87
88#endif  // CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_VIEW_MAC_H_
89