15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_H_
6010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
11010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "base/strings/string16.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/content_export.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/native_widget_types.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/rect.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/size.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
18010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)class RenderViewHost;
19010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)class RenderWidgetHost;
20010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)class RenderWidgetHostViewBase;
21eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochstruct DropData;
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The WebContentsView is an interface that is implemented by the platform-
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// dependent web contents views. The WebContents uses this interface to talk to
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// them.
26010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)class WebContentsView {
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~WebContentsView() {}
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the native widget that contains the contents of the tab.
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual gfx::NativeView GetNativeView() const = 0;
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the native widget with the main content of the tab (i.e. the main
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // render view host, though there may be many popups in the tab as children of
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the container).
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual gfx::NativeView GetContentNativeView() const = 0;
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the outermost native view. This will be used as the parent for
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // dialog boxes.
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual gfx::NativeWindow GetTopLevelNativeWindow() const = 0;
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Computes the rectangle for the native widget that contains the contents of
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the tab in the screen coordinate system.
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void GetContainerBounds(gfx::Rect* out) const = 0;
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(brettw) this is a hack. It's used in two places at the time of this
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // writing: (1) when render view hosts switch, we need to size the replaced
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // one to be correct, since it wouldn't have known about sizes that happened
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // while it was hidden; (2) in constrained windows.
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // (1) will be fixed once interstitials are cleaned up. (2) seems like it
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // should be cleaned up or done some other way, since this works for normal
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // WebContents without the special code.
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SizeContents(const gfx::Size& size) = 0;
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets focus to the native widget for this tab.
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Focus() = 0;
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets focus to the appropriate element when the WebContents is shown the
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // first time.
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetInitialFocus() = 0;
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stores the currently focused view.
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void StoreFocus() = 0;
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Restores focus to the last focus view. If StoreFocus has not yet been
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // invoked, SetInitialFocus is invoked.
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RestoreFocus() = 0;
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the current drop data, if any.
71eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual DropData* GetDropData() const = 0;
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get the bounds of the View, relative to the parent.
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual gfx::Rect GetViewBounds() const = 0;
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
76010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual void CreateView(
77010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      const gfx::Size& initial_size, gfx::NativeView context) = 0;
78010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
79010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Sets up the View that holds the rendered web page, receives messages for
80010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // it and contains page plugins. The host view should be sized to the current
81010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // size of the WebContents.
82010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual RenderWidgetHostViewBase* CreateViewForWidget(
83010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      RenderWidgetHost* render_widget_host) = 0;
84010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
85010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Creates a new View that holds a popup and receives messages for it.
86010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual RenderWidgetHostViewBase* CreateViewForPopupWidget(
87010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      RenderWidgetHost* render_widget_host) = 0;
88010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
89010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Sets the page title for the native widgets corresponding to the view. This
90010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // is not strictly necessary and isn't expected to be displayed anywhere, but
91010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // can aid certain debugging tools such as Spy++ on Windows where you are
92010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // trying to find a specific window.
93010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual void SetPageTitle(const base::string16& title) = 0;
94010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
95010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Invoked when the WebContents is notified that the RenderView has been
96010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // fully created.
97010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual void RenderViewCreated(RenderViewHost* host) = 0;
98010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
99010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Invoked when the WebContents is notified that the RenderView has been
100010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // swapped in.
101010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual void RenderViewSwappedIn(RenderViewHost* host) = 0;
102010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
103010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Invoked to enable/disable overscroll gesture navigation.
104010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual void SetOverscrollControllerEnabled(bool enabled) = 0;
105010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_MACOSX)
107116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Allowing other views disables optimizations which assume that only a single
108116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // WebContents is present.
109116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual void SetAllowOtherViews(bool allow) = 0;
110116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
111116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Returns true if other views are allowed, false otherwise.
112116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual bool GetAllowOtherViews() const = 0;
113010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
114010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // If we close the tab while a UI control is in an event-tracking
115010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // loop, the control may message freed objects and crash.
116010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // WebContents::Close() calls IsEventTracking(), and if it returns
117010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // true CloseTabAfterEventTracking() is called and the close is not
118010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // completed.
119010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual bool IsEventTracking() const = 0;
120010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual void CloseTabAfterEventTracking() = 0;
1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace content
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
126010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#endif  // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_H_
127