OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ | 5 #ifndef UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ |
6 #define UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ | 6 #define UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "content/public/browser/notification_observer.h" |
| 11 #include "content/public/browser/notification_registrar.h" |
10 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/browser/web_contents_delegate.h" |
11 #include "ui/views/view.h" | 14 #include "ui/views/view.h" |
12 | 15 |
13 namespace views { | 16 namespace views { |
14 | 17 |
15 class NativeViewHost; | 18 class NativeViewHost; |
16 | 19 |
17 class VIEWS_EXPORT WebView : public View { | 20 class VIEWS_EXPORT WebView : public View, |
| 21 public content::NotificationObserver, |
| 22 public content::WebContentsDelegate { |
18 public: | 23 public: |
19 explicit WebView(content::BrowserContext* browser_context); | 24 explicit WebView(content::BrowserContext* browser_context); |
20 virtual ~WebView(); | 25 virtual ~WebView(); |
21 | 26 |
22 content::WebContents* web_contents() { return web_contents_.get(); } | 27 // This creates a WebContents if none is yet associated with this WebView. The |
| 28 // WebView owns this implicitly created WebContents. |
| 29 content::WebContents* GetWebContents(); |
| 30 |
| 31 // WebView does not assume ownership of WebContents set via this method, only |
| 32 // those it implicitly creates via GetWebContents() above. |
| 33 void SetWebContents(content::WebContents* web_contents); |
| 34 |
| 35 content::WebContents* web_contents() { return web_contents_; } |
| 36 |
| 37 // Controls how the attached WebContents is resized. |
| 38 // false = WebContents' views' bounds are updated continuously as the |
| 39 // WebView's bounds change (default). |
| 40 // true = WebContents' views' position is updated continuously but its size |
| 41 // is not (which may result in some clipping or under-painting) until |
| 42 // a continuous size operation completes. This allows for smoother |
| 43 // resizing performance during interactive resizes and animations. |
| 44 void SetFastResize(bool fast_resize); |
| 45 |
| 46 // Called when the WebContents is focused. |
| 47 // TODO(beng): This view should become a WebContentsViewObserver when a |
| 48 // WebContents is attached, and not rely on the delegate to |
| 49 // forward this notification. |
| 50 void OnWebContentsFocused(content::WebContents* web_contents); |
23 | 51 |
24 private: | 52 private: |
25 void Init(); | |
26 | |
27 // Overridden from View: | 53 // Overridden from View: |
28 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; | 54 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; |
29 virtual void ViewHierarchyChanged(bool is_add, | 55 virtual void ViewHierarchyChanged(bool is_add, |
30 View* parent, | 56 View* parent, |
31 View* child) OVERRIDE; | 57 View* child) OVERRIDE; |
| 58 virtual bool SkipDefaultKeyEventProcessing( |
| 59 const views::KeyEvent& event) OVERRIDE; |
| 60 virtual bool IsFocusable() const OVERRIDE; |
| 61 virtual void OnFocus() OVERRIDE; |
| 62 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE; |
| 63 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
| 64 virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE; |
| 65 |
| 66 // Overridden from content::NotificationObserver: |
| 67 virtual void Observe(int type, |
| 68 const content::NotificationSource& source, |
| 69 const content::NotificationDetails& details) OVERRIDE; |
| 70 |
| 71 // Overridden from content::WebContentsDelegate: |
| 72 virtual void WebContentsFocused(content::WebContents* web_contents) OVERRIDE; |
| 73 |
| 74 void AttachWebContents(); |
| 75 void DetachWebContents(); |
| 76 |
| 77 void RenderViewHostChanged(content::RenderViewHost* old_host, |
| 78 content::RenderViewHost* new_host); |
| 79 void WebContentsDestroyed(content::WebContents* web_contents); |
32 | 80 |
33 NativeViewHost* wcv_holder_; | 81 NativeViewHost* wcv_holder_; |
34 scoped_ptr<content::WebContents> web_contents_; | 82 scoped_ptr<content::WebContents> wc_owner_; |
| 83 content::WebContents* web_contents_; |
35 content::BrowserContext* browser_context_; | 84 content::BrowserContext* browser_context_; |
| 85 content::NotificationRegistrar registrar_; |
36 | 86 |
37 DISALLOW_COPY_AND_ASSIGN(WebView); | 87 DISALLOW_COPY_AND_ASSIGN(WebView); |
38 }; | 88 }; |
39 | 89 |
40 } // namespace views | 90 } // namespace views |
41 | 91 |
42 #endif // UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ | 92 #endif // UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ |
OLD | NEW |