diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 02:37:45 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 02:37:45 +0000 |
commit | 81af939f99865071091db5393e87d85fb0f02012 (patch) | |
tree | baeac357d60dbc5286e782bfbc650819a8bb826a /chrome/browser/tab_contents/tab_contents_view.h | |
parent | 1b157c09daab66d1f322eb47870ca8d3ba70c381 (diff) | |
download | chromium_src-81af939f99865071091db5393e87d85fb0f02012.zip chromium_src-81af939f99865071091db5393e87d85fb0f02012.tar.gz chromium_src-81af939f99865071091db5393e87d85fb0f02012.tar.bz2 |
Rename web_contents_view* files to tab_contents_view* to reflect my previous
rename of the classes.
Review URL: http://codereview.chromium.org/87009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14083 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents/tab_contents_view.h')
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view.h | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/chrome/browser/tab_contents/tab_contents_view.h b/chrome/browser/tab_contents/tab_contents_view.h new file mode 100644 index 0000000..2a17dff --- /dev/null +++ b/chrome/browser/tab_contents/tab_contents_view.h @@ -0,0 +1,180 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_H_ +#define CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_H_ + +#include <map> +#include <string> + +#include "base/basictypes.h" +#include "base/gfx/native_widget_types.h" +#include "base/gfx/rect.h" +#include "base/gfx/size.h" +#include "chrome/browser/renderer_host/render_view_host_delegate.h" +#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" + +class Browser; +class RenderViewHost; +class RenderWidgetHost; +class RenderWidgetHostView; +class WebContents; +class WebKeyboardEvent; + +namespace base { +class WaitableEvent; +} + +// The TabContentsView is an interface that is implemented by the platform- +// dependent web contents views. The WebContents uses this interface to talk to +// them. View-related messages will also get forwarded directly to this class +// from RenderViewHost via RenderViewHostDelegate::View. +// +// It contains a small amount of logic with respect to creating new sub-view +// that should be the same for all platforms. +class TabContentsView : public RenderViewHostDelegate::View { + public: + explicit TabContentsView(WebContents* web_contents); + virtual ~TabContentsView() {} + + // Creates the appropriate type of TabContentsView for the current system. + // The return value is a new heap allocated view with ownership passing to + // the caller. + static TabContentsView* Create(WebContents* web_contents); + + WebContents* web_contents() const { return web_contents_; } + + virtual void CreateView() = 0; + + // Sets up the View that holds the rendered web page, receives messages for + // it and contains page plugins. The host view should be sized to the current + // size of the WebContents. + virtual RenderWidgetHostView* CreateViewForWidget( + RenderWidgetHost* render_widget_host) = 0; + + // Returns the native widget that contains the contents of the tab. + virtual gfx::NativeView GetNativeView() const = 0; + + // Returns the native widget with the main content of the tab (i.e. the main + // render view host, though there may be many popups in the tab as children of + // the container). + virtual gfx::NativeView GetContentNativeView() const = 0; + + // Returns the outermost native view. This will be used as the parent for + // dialog boxes. + virtual gfx::NativeWindow GetTopLevelNativeWindow() const = 0; + + // Computes the rectangle for the native widget that contains the contents of + // the tab relative to its parent. + virtual void GetContainerBounds(gfx::Rect *out) const = 0; + + // Helper function for GetContainerBounds. Most callers just want to know the + // size, and this makes it more clear. + gfx::Size GetContainerSize() const { + gfx::Rect rc; + GetContainerBounds(&rc); + return gfx::Size(rc.width(), rc.height()); + } + + // Called when the WebContents is being destroyed. This should clean up child + // windows that are part of the view. + // + // TODO(brettw) It seems like this might be able to be done internally as the + // window is being torn down without input from the WebContents. Try to + // implement functions that way rather than adding stuff here. + virtual void OnContentsDestroy() = 0; + + // Sets the page title for the native widgets corresponding to the view. This + // is not strictly necessary and isn't expected to be displayed anywhere, but + // can aid certain debugging tools such as Spy++ on Windows where you are + // trying to find a specific window. + virtual void SetPageTitle(const std::wstring& title) = 0; + + // Schedules a complete repaint of the window. This is used for cases where + // the existing contents became invalid due to an external event, such as the + // renderer crashing. + virtual void Invalidate() = 0; + + // TODO(brettw) this is a hack. It's used in two places at the time of this + // writing: (1) when render view hosts switch, we need to size the replaced + // one to be correct, since it wouldn't have known about sizes that happened + // while it was hidden; (2) in constrained windows. + // + // (1) will be fixed once interstitials are cleaned up. (2) seems like it + // should be cleaned up or done some other way, since this works for normal + // TabContents without the special code. + virtual void SizeContents(const gfx::Size& size) = 0; + + // Invoked from the platform dependent web contents view when a + // RenderWidgetHost is deleted. Removes |host| from internal maps. + void RenderWidgetHostDestroyed(RenderWidgetHost* host); + + // Sets focus to the native widget for this tab. + virtual void Focus() = 0; + + // Sets focus to the appropriate element when the tab contents is shown the + // first time. + virtual void SetInitialFocus() = 0; + + // Stores the currently focused view. + virtual void StoreFocus() = 0; + + // Restores focus to the last focus view. If StoreFocus has not yet been + // invoked, SetInitialFocus is invoked. + virtual void RestoreFocus() = 0; + + // Sets children's size. May involve packing them in order to get the + // toolkit to send them resize events. + virtual void SetChildSize(RenderWidgetHostView* rwh_view) = 0; + + protected: + TabContentsView() {} // Abstract interface. + + // Internal functions used to support the CreateNewWidget() method. If a + // platform requires plugging into widget creation at a lower level then a + // subclass might want to override these functions, but otherwise they should + // be fine just implementing RenderWidgetHostView::InitAsPopup(). + // + // The Create function returns the newly created widget so it can be + // associated with the given route. When the widget needs to be shown later, + // we'll look it up again and pass the object to the Show functions rather + // than the route ID. + virtual RenderWidgetHostView* CreateNewWidgetInternal(int route_id, + bool activatable); + virtual void ShowCreatedWidgetInternal(RenderWidgetHostView* widget_host_view, + const gfx::Rect& initial_pos); + + // Common implementations of some RenderViewHostDelegate::View methods. + RenderViewHostDelegateViewHelper delegate_view_helper_; + + private: + // We implement these functions on RenderViewHostDelegate::View directly and + // do some book-keeping associated with the request. The request is then + // forwarded to *Internal which does platform-specific work. + virtual void CreateNewWindow(int route_id, + base::WaitableEvent* modal_dialog_event); + virtual void CreateNewWidget(int route_id, bool activatable); + virtual void ShowCreatedWindow(int route_id, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture); + virtual void ShowCreatedWidget(int route_id, const gfx::Rect& initial_pos); + + // The WebContents whose contents we display. + WebContents* web_contents_; + + // Tracks created WebContents objects that have not been shown yet. They are + // identified by the route ID passed to CreateNewWindow. + typedef std::map<int, WebContents*> PendingContents; + PendingContents pending_contents_; + + // These maps hold on to the widgets that we created on behalf of the + // renderer that haven't shown yet. + typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews; + PendingWidgetViews pending_widget_views_; + + DISALLOW_COPY_AND_ASSIGN(TabContentsView); +}; + +#endif // CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_H_ |