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_PUBLIC_BROWSER_WEB_CONTENTS_VIEW_H_ 6 #define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_VIEW_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/process/kill.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 struct DropData; 19 20 // The WebContentsView is an interface that is implemented by the platform- 21 // dependent web contents views. The WebContents uses this interface to talk to 22 // them. 23 class CONTENT_EXPORT WebContentsView { 24 public: ~WebContentsView()25 virtual ~WebContentsView() {} 26 27 // Returns the native widget that contains the contents of the tab. 28 virtual gfx::NativeView GetNativeView() const = 0; 29 30 // Returns the native widget with the main content of the tab (i.e. the main 31 // render view host, though there may be many popups in the tab as children of 32 // the container). 33 virtual gfx::NativeView GetContentNativeView() const = 0; 34 35 // Returns the outermost native view. This will be used as the parent for 36 // dialog boxes. 37 virtual gfx::NativeWindow GetTopLevelNativeWindow() const = 0; 38 39 // Computes the rectangle for the native widget that contains the contents of 40 // the tab in the screen coordinate system. 41 virtual void GetContainerBounds(gfx::Rect* out) const = 0; 42 43 // Helper function for GetContainerBounds. Most callers just want to know the 44 // size, and this makes it more clear. GetContainerSize()45 gfx::Size GetContainerSize() const { 46 gfx::Rect rc; 47 GetContainerBounds(&rc); 48 return gfx::Size(rc.width(), rc.height()); 49 } 50 51 // Used to notify the view that a tab has crashed. 52 virtual void OnTabCrashed(base::TerminationStatus status, int error_code) = 0; 53 54 // TODO(brettw) this is a hack. It's used in two places at the time of this 55 // writing: (1) when render view hosts switch, we need to size the replaced 56 // one to be correct, since it wouldn't have known about sizes that happened 57 // while it was hidden; (2) in constrained windows. 58 // 59 // (1) will be fixed once interstitials are cleaned up. (2) seems like it 60 // should be cleaned up or done some other way, since this works for normal 61 // WebContents without the special code. 62 virtual void SizeContents(const gfx::Size& size) = 0; 63 64 // Sets focus to the native widget for this tab. 65 virtual void Focus() = 0; 66 67 // Sets focus to the appropriate element when the WebContents is shown the 68 // first time. 69 virtual void SetInitialFocus() = 0; 70 71 // Stores the currently focused view. 72 virtual void StoreFocus() = 0; 73 74 // Restores focus to the last focus view. If StoreFocus has not yet been 75 // invoked, SetInitialFocus is invoked. 76 virtual void RestoreFocus() = 0; 77 78 // Returns the current drop data, if any. 79 virtual DropData* GetDropData() const = 0; 80 81 // Get the bounds of the View, relative to the parent. 82 virtual gfx::Rect GetViewBounds() const = 0; 83 84 #if defined(OS_MACOSX) 85 // The web contents view assumes that its view will never be overlapped by 86 // another view (either partially or fully). This allows it to perform 87 // optimizations. If the view is in a view hierarchy where it might be 88 // overlapped by another view, notify the view by calling this with |true|. 89 virtual void SetAllowOverlappingViews(bool overlapping) = 0; 90 91 // Returns true if overlapping views are allowed, false otherwise. 92 virtual bool GetAllowOverlappingViews() const = 0; 93 94 // To draw two overlapping web contents view, the underlaying one should 95 // know about the overlaying one. Caller must ensure that |overlay| exists 96 // until |RemoveOverlayView| is called. 97 virtual void SetOverlayView(WebContentsView* overlay, 98 const gfx::Point& offset) = 0; 99 100 // Removes the previously set overlay view. 101 virtual void RemoveOverlayView() = 0; 102 #endif 103 }; 104 105 } // namespace content 106 107 #endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_VIEW_H_ 108