summaryrefslogtreecommitdiffstats
path: root/ui/views/controls
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-14 01:10:19 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-14 01:10:19 +0000
commit2bed8faa3d86ede787eb97ef2d87b679b830446c (patch)
treecabad51bab9873af4aa33a4d25592df52718a3cc /ui/views/controls
parenta3f773fb59bc3f148c627bb616f61b72b98f40b9 (diff)
downloadchromium_src-2bed8faa3d86ede787eb97ef2d87b679b830446c.zip
chromium_src-2bed8faa3d86ede787eb97ef2d87b679b830446c.tar.gz
chromium_src-2bed8faa3d86ede787eb97ef2d87b679b830446c.tar.bz2
Revert 132281 - Add more functionality to WebView.
- Ability for WebContents to be replaced. - Various focus/destruction observers. - Hook up to BrowserView, replacing TabContentsContainer. BUG=none TEST=none Review URL: https://chromiumcodereview.appspot.com/10073014 TBR=ben@chromium.org Review URL: https://chromiumcodereview.appspot.com/10086026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132306 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/controls')
-rw-r--r--ui/views/controls/webview/webview.cc175
-rw-r--r--ui/views/controls/webview/webview.h60
2 files changed, 14 insertions, 221 deletions
diff --git a/ui/views/controls/webview/webview.cc b/ui/views/controls/webview/webview.cc
index 4de68b5..864ec1dd 100644
--- a/ui/views/controls/webview/webview.cc
+++ b/ui/views/controls/webview/webview.cc
@@ -5,17 +5,8 @@
#include "ui/views/controls/webview/webview.h"
#include "content/public/browser/browser_context.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_registrar.h"
-#include "content/public/browser/notification_source.h"
-#include "content/public/browser/notification_types.h"
-#include "content/public/browser/render_view_host.h"
-#include "content/public/browser/render_widget_host_view.h"
#include "ipc/ipc_message.h"
-#include "ui/base/accessibility/accessible_view_state.h"
-#include "ui/base/accessibility/accessibility_types.h"
#include "ui/views/controls/native/native_view_host.h"
-#include "ui/views/focus/focus_manager.h"
namespace views {
@@ -24,49 +15,21 @@ namespace views {
WebView::WebView(content::BrowserContext* browser_context)
: wcv_holder_(new NativeViewHost),
- web_contents_(NULL),
browser_context_(browser_context) {
- AddChildView(wcv_holder_);
+ Init();
}
WebView::~WebView() {
}
-content::WebContents* WebView::GetWebContents() {
- if (!web_contents_) {
- wc_owner_.reset(content::WebContents::Create(browser_context_,
- NULL,
- MSG_ROUTING_NONE,
- NULL,
- NULL));
- web_contents_ = wc_owner_.get();
- web_contents_->SetDelegate(this);
- AttachWebContents();
- }
- return web_contents_;
-}
-
-void WebView::SetWebContents(content::WebContents* web_contents) {
- if (web_contents == web_contents_)
- return;
- DetachWebContents();
- wc_owner_.reset();
- web_contents_ = web_contents;
- AttachWebContents();
-}
-
-void WebView::SetFastResize(bool fast_resize) {
- wcv_holder_->set_fast_resize(fast_resize);
-}
+////////////////////////////////////////////////////////////////////////////////
+// WebView, private:
-void WebView::OnWebContentsFocused(content::WebContents* web_contents) {
- DCHECK(web_contents == web_contents_);
- FocusManager* focus_manager = GetFocusManager();
- if (!focus_manager) {
- NOTREACHED();
- return;
- }
- focus_manager->SetFocusedView(this);
+void WebView::Init() {
+ AddChildView(wcv_holder_);
+ web_contents_.reset(
+ content::WebContents::Create(browser_context_, NULL, MSG_ROUTING_NONE,
+ NULL, NULL));
}
////////////////////////////////////////////////////////////////////////////////
@@ -77,128 +40,8 @@ void WebView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
}
void WebView::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
- if (is_add)
- AttachWebContents();
-}
-
-bool WebView::SkipDefaultKeyEventProcessing(const views::KeyEvent& event) {
- // Don't look-up accelerators or tab-traversal if we are showing a non-crashed
- // TabContents.
- // We'll first give the page a chance to process the key events. If it does
- // not process them, they'll be returned to us and we'll treat them as
- // accelerators then.
- return web_contents_ && !web_contents_->IsCrashed();
-}
-
-bool WebView::IsFocusable() const {
- // We need to be focusable when our contents is not a view hierarchy, as
- // clicking on the contents needs to focus us.
- return !!web_contents_;
-}
-
-void WebView::OnFocus() {
- if (web_contents_)
- web_contents_->Focus();
-}
-
-void WebView::AboutToRequestFocusFromTabTraversal(bool reverse) {
- if (web_contents_)
- web_contents_->FocusThroughTabTraversal(reverse);
-}
-
-void WebView::GetAccessibleState(ui::AccessibleViewState* state) {
- state->role = ui::AccessibilityTypes::ROLE_GROUPING;
-}
-
-gfx::NativeViewAccessible WebView::GetNativeViewAccessible() {
- if (web_contents_) {
- content::RenderWidgetHostView* host_view =
- web_contents_->GetRenderWidgetHostView();
- if (host_view)
- return host_view->GetNativeViewAccessible();
- }
- return View::GetNativeViewAccessible();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// WebView, content::NotificationObserver implementation:
-
-void WebView::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- if (type == content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED) {
- std::pair<content::RenderViewHost*, content::RenderViewHost*>*
- switched_details =
- content::Details<std::pair<content::RenderViewHost*,
- content::RenderViewHost*> >(
- details).ptr();
- RenderViewHostChanged(switched_details->first,
- switched_details->second);
- } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) {
- WebContentsDestroyed(content::Source<content::WebContents>(source).ptr());
- } else {
- NOTREACHED();
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// WebView, content::WebContentsDelegate implementation:
-
-void WebView::WebContentsFocused(content::WebContents* web_contents) {
- DCHECK(wc_owner_.get());
- // The WebView is only the delegate of WebContentses it creates itself.
- WebContentsFocused(web_contents_);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// WebView, private:
-
-void WebView::AttachWebContents() {
- // Prevents attachment if the WebView isn't already in a Widget, or it's
- // already attached.
- if (!GetWidget() || !web_contents_ ||
- wcv_holder_->native_view() == web_contents_->GetNativeView()) {
- return;
- }
-
- if (web_contents_) {
+ if (is_add && child == this)
wcv_holder_->Attach(web_contents_->GetNativeView());
-
- registrar_.Add(
- this,
- content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
- content::Source<content::NavigationController>(
- &web_contents_->GetController()));
- registrar_.Add(
- this,
- content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
- content::Source<content::WebContents>(web_contents_));
- }
-}
-
-void WebView::DetachWebContents() {
- if (web_contents_) {
- wcv_holder_->Detach();
-#if defined(OS_WIN)
- // TODO(beng): This should either not be necessary, or be done implicitly by
- // NativeViewHostWin on Detach(). As it stands, this is needed
- // so that the view of the detached contents knows to tell the
- // renderer its been hidden.
- ShowWindow(web_contents_->GetNativeView(), SW_HIDE);
-#endif
- }
- registrar_.RemoveAll();
-}
-
-void WebView::RenderViewHostChanged(content::RenderViewHost* old_host,
- content::RenderViewHost* new_host) {
- if (GetFocusManager()->GetFocusedView() == this)
- web_contents_->Focus();
-}
-
-void WebView::WebContentsDestroyed(content::WebContents* web_contents) {
- DCHECK(web_contents == web_contents_);
- SetWebContents(NULL);
}
} // namespace views
diff --git a/ui/views/controls/webview/webview.h b/ui/views/controls/webview/webview.h
index 23c4748..c817d97 100644
--- a/ui/views/controls/webview/webview.h
+++ b/ui/views/controls/webview/webview.h
@@ -7,82 +7,32 @@
#pragma once
#include "base/memory/scoped_ptr.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_delegate.h"
#include "ui/views/view.h"
namespace views {
class NativeViewHost;
-class VIEWS_EXPORT WebView : public View,
- public content::NotificationObserver,
- public content::WebContentsDelegate {
+class VIEWS_EXPORT WebView : public View {
public:
explicit WebView(content::BrowserContext* browser_context);
virtual ~WebView();
- // This creates a WebContents if none is yet associated with this WebView. The
- // WebView owns this implicitly created WebContents.
- content::WebContents* GetWebContents();
-
- // WebView does not assume ownership of WebContents set via this method, only
- // those it implicitly creates via GetWebContents() above.
- void SetWebContents(content::WebContents* web_contents);
-
- content::WebContents* web_contents() { return web_contents_; }
-
- // Controls how the attached WebContents is resized.
- // false = WebContents' views' bounds are updated continuously as the
- // WebView's bounds change (default).
- // true = WebContents' views' position is updated continuously but its size
- // is not (which may result in some clipping or under-painting) until
- // a continuous size operation completes. This allows for smoother
- // resizing performance during interactive resizes and animations.
- void SetFastResize(bool fast_resize);
-
- // Called when the WebContents is focused.
- // TODO(beng): This view should become a WebContentsViewObserver when a
- // WebContents is attached, and not rely on the delegate to
- // forward this notification.
- void OnWebContentsFocused(content::WebContents* web_contents);
+ content::WebContents* web_contents() { return web_contents_.get(); }
private:
+ void Init();
+
// Overridden from View:
virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
virtual void ViewHierarchyChanged(bool is_add,
View* parent,
View* child) OVERRIDE;
- virtual bool SkipDefaultKeyEventProcessing(
- const views::KeyEvent& event) OVERRIDE;
- virtual bool IsFocusable() const OVERRIDE;
- virtual void OnFocus() OVERRIDE;
- virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE;
- virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
- virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
-
- // Overridden from content::NotificationObserver:
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
-
- // Overridden from content::WebContentsDelegate:
- virtual void WebContentsFocused(content::WebContents* web_contents) OVERRIDE;
-
- void AttachWebContents();
- void DetachWebContents();
-
- void RenderViewHostChanged(content::RenderViewHost* old_host,
- content::RenderViewHost* new_host);
- void WebContentsDestroyed(content::WebContents* web_contents);
NativeViewHost* wcv_holder_;
- scoped_ptr<content::WebContents> wc_owner_;
- content::WebContents* web_contents_;
+ scoped_ptr<content::WebContents> web_contents_;
content::BrowserContext* browser_context_;
- content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(WebView);
};