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" | |
12 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
13 #include "content/public/browser/web_contents_delegate.h" | |
14 #include "ui/views/view.h" | 11 #include "ui/views/view.h" |
15 | 12 |
16 namespace views { | 13 namespace views { |
17 | 14 |
18 class NativeViewHost; | 15 class NativeViewHost; |
19 | 16 |
20 class VIEWS_EXPORT WebView : public View, | 17 class VIEWS_EXPORT WebView : public View { |
21 public content::NotificationObserver, | |
22 public content::WebContentsDelegate { | |
23 public: | 18 public: |
24 explicit WebView(content::BrowserContext* browser_context); | 19 explicit WebView(content::BrowserContext* browser_context); |
25 virtual ~WebView(); | 20 virtual ~WebView(); |
26 | 21 |
27 // This creates a WebContents if none is yet associated with this WebView. The | 22 content::WebContents* web_contents() { return web_contents_.get(); } |
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); | |
51 | 23 |
52 private: | 24 private: |
| 25 void Init(); |
| 26 |
53 // Overridden from View: | 27 // Overridden from View: |
54 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; | 28 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; |
55 virtual void ViewHierarchyChanged(bool is_add, | 29 virtual void ViewHierarchyChanged(bool is_add, |
56 View* parent, | 30 View* parent, |
57 View* child) OVERRIDE; | 31 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); | |
80 | 32 |
81 NativeViewHost* wcv_holder_; | 33 NativeViewHost* wcv_holder_; |
82 scoped_ptr<content::WebContents> wc_owner_; | 34 scoped_ptr<content::WebContents> web_contents_; |
83 content::WebContents* web_contents_; | |
84 content::BrowserContext* browser_context_; | 35 content::BrowserContext* browser_context_; |
85 content::NotificationRegistrar registrar_; | |
86 | 36 |
87 DISALLOW_COPY_AND_ASSIGN(WebView); | 37 DISALLOW_COPY_AND_ASSIGN(WebView); |
88 }; | 38 }; |
89 | 39 |
90 } // namespace views | 40 } // namespace views |
91 | 41 |
92 #endif // UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ | 42 #endif // UI_VIEWS_CONTROLS_WEBVIEW_WEBVIEW_H_ |
OLD | NEW |