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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_VIEW_VIEWS_H_
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_VIEW_VIEWS_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "content/public/browser/native_web_keyboard_event.h"
11 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "ui/views/controls/native/native_view_host.h"
13 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
21 namespace extensions {
26 // This handles the display portion of an ExtensionHost.
27 class ExtensionViewViews : public views::NativeViewHost {
29 ExtensionViewViews(extensions::ExtensionHost* host, Browser* browser);
30 virtual ~ExtensionViewViews();
32 // A class that represents the container that this view is in.
33 // (bottom shelf, side bar, etc.)
36 virtual ~Container() {}
37 virtual void OnExtensionSizeChanged(ExtensionViewViews* view) {}
38 virtual void OnViewWasResized() {}
41 extensions::ExtensionHost* host() const { return host_; }
42 Browser* browser() const { return browser_; }
43 const extensions::Extension* extension() const;
44 content::RenderViewHost* render_view_host() const;
45 void DidStopLoading();
46 void SetIsClipped(bool is_clipped);
48 // Notification from ExtensionHost.
49 void ResizeDueToAutoResize(const gfx::Size& new_size);
51 // Method for the ExtensionHost to notify us when the RenderViewHost has a
53 void RenderViewCreated();
55 // Sets the container for this view.
56 void SetContainer(Container* container) { container_ = container; }
58 // Handles unhandled keyboard messages coming back from the renderer process.
59 void HandleKeyboardEvent(const content::NativeWebKeyboardEvent& event);
61 // Overridden from views::NativeViewHost:
62 virtual gfx::NativeCursor GetCursor(const ui::MouseEvent& event) OVERRIDE;
63 virtual void SetVisible(bool is_visible) OVERRIDE;
64 virtual void ViewHierarchyChanged(
65 const ViewHierarchyChangedDetails& details) OVERRIDE;
68 // Overridden from views::View.
69 virtual bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) OVERRIDE;
70 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
71 virtual void PreferredSizeChanged() OVERRIDE;
72 virtual void OnFocus() OVERRIDE;
75 friend class extensions::ExtensionHost;
77 // Initializes the RenderWidgetHostView for this object.
78 void CreateWidgetHostView();
80 // We wait to show the ExtensionViewViews until several things have loaded.
81 void ShowIfCompletelyLoaded();
83 // Restore object to initial state. Called on shutdown or after a renderer
87 // The running extension instance that we're displaying.
88 // Note that host_ owns view
89 extensions::ExtensionHost* host_;
91 // The browser window that this view is in.
94 // True if we've been initialized.
97 // What we should set the preferred width to once the ExtensionViewViews has
99 gfx::Size pending_preferred_size_;
101 // The container this view is in (not necessarily its direct superview).
102 // Note: the view does not own its container.
103 Container* container_;
105 // Whether this extension view is clipped.
108 // A handler to handle unhandled keyboard messages coming back from the
110 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
112 DISALLOW_COPY_AND_ASSIGN(ExtensionViewViews);
115 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_VIEW_VIEWS_H_