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 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_H_ 6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/strings/string16.h" 12 #include "content/common/content_export.h" 13 #include "ui/gfx/native_widget_types.h" 14 #include "ui/gfx/rect.h" 15 #include "ui/gfx/size.h" 16 17 namespace content { 18 class RenderViewHost; 19 class RenderWidgetHost; 20 class RenderWidgetHostViewBase; 21 struct DropData; 22 23 // The WebContentsView is an interface that is implemented by the platform- 24 // dependent web contents views. The WebContents uses this interface to talk to 25 // them. 26 class WebContentsView { 27 public: 28 virtual ~WebContentsView() {} 29 30 // Returns the native widget that contains the contents of the tab. 31 virtual gfx::NativeView GetNativeView() const = 0; 32 33 // Returns the native widget with the main content of the tab (i.e. the main 34 // render view host, though there may be many popups in the tab as children of 35 // the container). 36 virtual gfx::NativeView GetContentNativeView() const = 0; 37 38 // Returns the outermost native view. This will be used as the parent for 39 // dialog boxes. 40 virtual gfx::NativeWindow GetTopLevelNativeWindow() const = 0; 41 42 // Computes the rectangle for the native widget that contains the contents of 43 // the tab in the screen coordinate system. 44 virtual void GetContainerBounds(gfx::Rect* out) const = 0; 45 46 // TODO(brettw) this is a hack. It's used in two places at the time of this 47 // writing: (1) when render view hosts switch, we need to size the replaced 48 // one to be correct, since it wouldn't have known about sizes that happened 49 // while it was hidden; (2) in constrained windows. 50 // 51 // (1) will be fixed once interstitials are cleaned up. (2) seems like it 52 // should be cleaned up or done some other way, since this works for normal 53 // WebContents without the special code. 54 virtual void SizeContents(const gfx::Size& size) = 0; 55 56 // Sets focus to the native widget for this tab. 57 virtual void Focus() = 0; 58 59 // Sets focus to the appropriate element when the WebContents is shown the 60 // first time. 61 virtual void SetInitialFocus() = 0; 62 63 // Stores the currently focused view. 64 virtual void StoreFocus() = 0; 65 66 // Restores focus to the last focus view. If StoreFocus has not yet been 67 // invoked, SetInitialFocus is invoked. 68 virtual void RestoreFocus() = 0; 69 70 // Returns the current drop data, if any. 71 virtual DropData* GetDropData() const = 0; 72 73 // Get the bounds of the View, relative to the parent. 74 virtual gfx::Rect GetViewBounds() const = 0; 75 76 virtual void CreateView( 77 const gfx::Size& initial_size, gfx::NativeView context) = 0; 78 79 // Sets up the View that holds the rendered web page, receives messages for 80 // it and contains page plugins. The host view should be sized to the current 81 // size of the WebContents. 82 virtual RenderWidgetHostViewBase* CreateViewForWidget( 83 RenderWidgetHost* render_widget_host) = 0; 84 85 // Creates a new View that holds a popup and receives messages for it. 86 virtual RenderWidgetHostViewBase* CreateViewForPopupWidget( 87 RenderWidgetHost* render_widget_host) = 0; 88 89 // Sets the page title for the native widgets corresponding to the view. This 90 // is not strictly necessary and isn't expected to be displayed anywhere, but 91 // can aid certain debugging tools such as Spy++ on Windows where you are 92 // trying to find a specific window. 93 virtual void SetPageTitle(const base::string16& title) = 0; 94 95 // Invoked when the WebContents is notified that the RenderView has been 96 // fully created. 97 virtual void RenderViewCreated(RenderViewHost* host) = 0; 98 99 // Invoked when the WebContents is notified that the RenderView has been 100 // swapped in. 101 virtual void RenderViewSwappedIn(RenderViewHost* host) = 0; 102 103 // Invoked to enable/disable overscroll gesture navigation. 104 virtual void SetOverscrollControllerEnabled(bool enabled) = 0; 105 106 #if defined(OS_MACOSX) 107 // The web contents view assumes that its view will never be overlapped by 108 // another view (either partially or fully). This allows it to perform 109 // optimizations. If the view is in a view hierarchy where it might be 110 // overlapped by another view, notify the view by calling this with |true|. 111 virtual void SetAllowOverlappingViews(bool overlapping) = 0; 112 113 // Returns true if overlapping views are allowed, false otherwise. 114 virtual bool GetAllowOverlappingViews() const = 0; 115 116 // To draw two overlapping web contents view, the underlaying one should 117 // know about the overlaying one. Caller must ensure that |overlay| exists 118 // until |RemoveOverlayView| is called. 119 virtual void SetOverlayView(WebContentsView* overlay, 120 const gfx::Point& offset) = 0; 121 122 // Removes the previously set overlay view. 123 virtual void RemoveOverlayView() = 0; 124 125 // If we close the tab while a UI control is in an event-tracking 126 // loop, the control may message freed objects and crash. 127 // WebContents::Close() calls IsEventTracking(), and if it returns 128 // true CloseTabAfterEventTracking() is called and the close is not 129 // completed. 130 virtual bool IsEventTracking() const = 0; 131 virtual void CloseTabAfterEventTracking() = 0; 132 #endif 133 }; 134 135 } // namespace content 136 137 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_H_ 138