| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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 #include "content/browser/web_contents/web_contents_view_mus.h" | |
| 6 | |
| 7 #include "build/build_config.h" | |
| 8 #include "content/browser/frame_host/interstitial_page_impl.h" | |
| 9 #include "content/browser/renderer_host/render_widget_host_view_mus.h" | |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | |
| 11 #include "content/public/browser/render_widget_host_view.h" | |
| 12 #include "content/public/browser/web_contents_view_delegate.h" | |
| 13 #include "services/ui/public/cpp/window.h" | |
| 14 #include "services/ui/public/cpp/window_tree_client.h" | |
| 15 #include "third_party/WebKit/public/platform/WebDragOperation.h" | |
| 16 #include "ui/aura/client/window_parenting_client.h" | |
| 17 #include "ui/aura/window.h" | |
| 18 #include "ui/base/hit_test.h" | |
| 19 | |
| 20 using blink::WebDragOperation; | |
| 21 using blink::WebDragOperationsMask; | |
| 22 | |
| 23 namespace content { | |
| 24 | |
| 25 WebContentsViewMus::WebContentsViewMus( | |
| 26 ui::Window* parent_window, | |
| 27 WebContentsImpl* web_contents, | |
| 28 WebContentsViewDelegate* delegate, | |
| 29 RenderViewHostDelegateView** delegate_view) | |
| 30 : web_contents_(web_contents), delegate_(delegate) { | |
| 31 DCHECK(parent_window); | |
| 32 *delegate_view = this; | |
| 33 ui::Window* window = parent_window->window_tree()->NewWindow(); | |
| 34 window->SetVisible(true); | |
| 35 window->SetBounds(gfx::Rect(300, 300)); | |
| 36 parent_window->AddChild(window); | |
| 37 mus_window_.reset(new ui::ScopedWindowPtr(window)); | |
| 38 } | |
| 39 | |
| 40 WebContentsViewMus::~WebContentsViewMus() {} | |
| 41 | |
| 42 void WebContentsViewMus::SizeChangedCommon(const gfx::Size& size) { | |
| 43 if (web_contents_->GetInterstitialPage()) | |
| 44 web_contents_->GetInterstitialPage()->SetSize(size); | |
| 45 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); | |
| 46 if (rwhv) | |
| 47 rwhv->SetSize(size); | |
| 48 mus_window_->window()->SetBounds(gfx::Rect(size)); | |
| 49 } | |
| 50 | |
| 51 gfx::NativeView WebContentsViewMus::GetNativeView() const { | |
| 52 return aura_window_.get(); | |
| 53 } | |
| 54 | |
| 55 gfx::NativeView WebContentsViewMus::GetContentNativeView() const { | |
| 56 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); | |
| 57 return rwhv ? rwhv->GetNativeView() : nullptr; | |
| 58 } | |
| 59 | |
| 60 gfx::NativeWindow WebContentsViewMus::GetTopLevelNativeWindow() const { | |
| 61 gfx::NativeWindow window = aura_window_->GetToplevelWindow(); | |
| 62 return window ? window : delegate_->GetNativeWindow(); | |
| 63 } | |
| 64 | |
| 65 void WebContentsViewMus::GetScreenInfo(ScreenInfo* screen_info) const { | |
| 66 // TODO(wjmaclean) Figure out what goes here. | |
| 67 } | |
| 68 | |
| 69 void WebContentsViewMus::GetContainerBounds(gfx::Rect* out) const { | |
| 70 *out = aura_window_->GetBoundsInScreen(); | |
| 71 } | |
| 72 | |
| 73 void WebContentsViewMus::SizeContents(const gfx::Size& size) { | |
| 74 gfx::Rect bounds = aura_window_->bounds(); | |
| 75 if (bounds.size() != size) { | |
| 76 bounds.set_size(size); | |
| 77 aura_window_->SetBounds(bounds); | |
| 78 SizeChangedCommon(size); | |
| 79 } else { | |
| 80 // Our size matches what we want but the renderers size may not match. | |
| 81 // Pretend we were resized so that the renderers size is updated too. | |
| 82 SizeChangedCommon(size); | |
| 83 } | |
| 84 } | |
| 85 | |
| 86 void WebContentsViewMus::SetInitialFocus() { | |
| 87 if (web_contents_->FocusLocationBarByDefault()) | |
| 88 web_contents_->SetFocusToLocationBar(false); | |
| 89 } | |
| 90 | |
| 91 gfx::Rect WebContentsViewMus::GetViewBounds() const { | |
| 92 return aura_window_->GetBoundsInScreen(); | |
| 93 } | |
| 94 | |
| 95 #if defined(OS_MACOSX) | |
| 96 void WebContentsViewMus::SetAllowOtherViews(bool allow) { | |
| 97 } | |
| 98 | |
| 99 bool WebContentsViewMus::GetAllowOtherViews() const { | |
| 100 return false; | |
| 101 } | |
| 102 #endif | |
| 103 | |
| 104 void WebContentsViewMus::CreateView(const gfx::Size& initial_size, | |
| 105 gfx::NativeView context) { | |
| 106 // We install a WindowDelegate so that the mus_window_ can track the size | |
| 107 // of the |aura_window_|. | |
| 108 aura_window_.reset(new aura::Window(this)); | |
| 109 aura_window_->set_owned_by_parent(false); | |
| 110 aura_window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); | |
| 111 aura_window_->Init(ui::LAYER_NOT_DRAWN); | |
| 112 aura::Window* root_window = context ? context->GetRootWindow() : nullptr; | |
| 113 if (root_window) { | |
| 114 // There are places where there is no context currently because object | |
| 115 // hierarchies are built before they're attached to a Widget. (See | |
| 116 // views::WebView as an example; GetWidget() returns nullptr at the point | |
| 117 // where we are created.) | |
| 118 // | |
| 119 // It should be OK to not set a default parent since such users will | |
| 120 // explicitly add this WebContentsViewMus to their tree after they create | |
| 121 // us. | |
| 122 aura::client::ParentWindowWithContext(aura_window_.get(), root_window, | |
| 123 root_window->GetBoundsInScreen()); | |
| 124 } | |
| 125 aura_window_->layer()->SetMasksToBounds(true); | |
| 126 aura_window_->SetName("WebContentsViewMus"); | |
| 127 } | |
| 128 | |
| 129 RenderWidgetHostViewBase* WebContentsViewMus::CreateViewForWidget( | |
| 130 RenderWidgetHost* render_widget_host, | |
| 131 bool is_guest_view_hack) { | |
| 132 RenderWidgetHostViewBase* view = new RenderWidgetHostViewMus( | |
| 133 mus_window_->window(), RenderWidgetHostImpl::From(render_widget_host)); | |
| 134 view->InitAsChild(GetNativeView()); | |
| 135 return view; | |
| 136 } | |
| 137 | |
| 138 RenderWidgetHostViewBase* WebContentsViewMus::CreateViewForPopupWidget( | |
| 139 RenderWidgetHost* render_widget_host) { | |
| 140 return new RenderWidgetHostViewMus( | |
| 141 mus_window_->window(), RenderWidgetHostImpl::From(render_widget_host)); | |
| 142 } | |
| 143 | |
| 144 void WebContentsViewMus::SetPageTitle(const base::string16& title) {} | |
| 145 | |
| 146 void WebContentsViewMus::RenderViewCreated(RenderViewHost* host) { | |
| 147 } | |
| 148 | |
| 149 void WebContentsViewMus::RenderViewSwappedIn(RenderViewHost* host) { | |
| 150 } | |
| 151 | |
| 152 void WebContentsViewMus::SetOverscrollControllerEnabled(bool enabled) { | |
| 153 // This should never override the setting of the embedder view. | |
| 154 } | |
| 155 | |
| 156 #if defined(OS_MACOSX) | |
| 157 bool WebContentsViewMus::IsEventTracking() const { | |
| 158 return false; | |
| 159 } | |
| 160 | |
| 161 void WebContentsViewMus::CloseTabAfterEventTracking() {} | |
| 162 #endif | |
| 163 | |
| 164 WebContents* WebContentsViewMus::web_contents() { | |
| 165 return web_contents_; | |
| 166 } | |
| 167 | |
| 168 void WebContentsViewMus::RestoreFocus() { | |
| 169 // Focus is managed by mus, not the browser. | |
| 170 NOTIMPLEMENTED(); | |
| 171 } | |
| 172 | |
| 173 void WebContentsViewMus::Focus() { | |
| 174 // Focus is managed by mus, not the browser. | |
| 175 NOTIMPLEMENTED(); | |
| 176 } | |
| 177 | |
| 178 void WebContentsViewMus::StoreFocus() { | |
| 179 // Focus is managed by mus, not the browser. | |
| 180 NOTIMPLEMENTED(); | |
| 181 } | |
| 182 | |
| 183 DropData* WebContentsViewMus::GetDropData() const { | |
| 184 NOTIMPLEMENTED(); | |
| 185 return nullptr; | |
| 186 } | |
| 187 | |
| 188 void WebContentsViewMus::UpdateDragCursor(WebDragOperation operation) { | |
| 189 // TODO(fsamuel): Implement cursor in Mus. | |
| 190 } | |
| 191 | |
| 192 void WebContentsViewMus::GotFocus() { | |
| 193 // Focus is managed by mus, not the browser. | |
| 194 NOTIMPLEMENTED(); | |
| 195 } | |
| 196 | |
| 197 void WebContentsViewMus::TakeFocus(bool reverse) { | |
| 198 // Focus is managed by mus, not the browser. | |
| 199 NOTIMPLEMENTED(); | |
| 200 } | |
| 201 | |
| 202 void WebContentsViewMus::ShowContextMenu(RenderFrameHost* render_frame_host, | |
| 203 const ContextMenuParams& params) { | |
| 204 } | |
| 205 | |
| 206 void WebContentsViewMus::StartDragging(const DropData& drop_data, | |
| 207 WebDragOperationsMask ops, | |
| 208 const gfx::ImageSkia& image, | |
| 209 const gfx::Vector2d& image_offset, | |
| 210 const DragEventSourceInfo& event_info, | |
| 211 RenderWidgetHostImpl* source_rwh) { | |
| 212 // TODO(fsamuel): Implement drag and drop. | |
| 213 } | |
| 214 | |
| 215 //////////////////////////////////////////////////////////////////////////////// | |
| 216 // WebContentsViewMus, aura::WindowDelegate implementation: | |
| 217 | |
| 218 gfx::Size WebContentsViewMus::GetMinimumSize() const { | |
| 219 return gfx::Size(); | |
| 220 } | |
| 221 | |
| 222 gfx::Size WebContentsViewMus::GetMaximumSize() const { | |
| 223 return gfx::Size(); | |
| 224 } | |
| 225 | |
| 226 void WebContentsViewMus::OnBoundsChanged(const gfx::Rect& old_bounds, | |
| 227 const gfx::Rect& new_bounds) { | |
| 228 SizeChangedCommon(new_bounds.size()); | |
| 229 if (delegate_) | |
| 230 delegate_->SizeChanged(new_bounds.size()); | |
| 231 } | |
| 232 | |
| 233 gfx::NativeCursor WebContentsViewMus::GetCursor(const gfx::Point& point) { | |
| 234 return gfx::kNullCursor; | |
| 235 } | |
| 236 | |
| 237 int WebContentsViewMus::GetNonClientComponent(const gfx::Point& point) const { | |
| 238 return HTCLIENT; | |
| 239 } | |
| 240 | |
| 241 bool WebContentsViewMus::ShouldDescendIntoChildForEventHandling( | |
| 242 aura::Window* child, | |
| 243 const gfx::Point& location) { | |
| 244 return true; | |
| 245 } | |
| 246 | |
| 247 bool WebContentsViewMus::CanFocus() { | |
| 248 return false; | |
| 249 } | |
| 250 | |
| 251 void WebContentsViewMus::OnCaptureLost() {} | |
| 252 | |
| 253 void WebContentsViewMus::OnPaint(const ui::PaintContext& context) {} | |
| 254 | |
| 255 void WebContentsViewMus::OnDeviceScaleFactorChanged(float device_scale_factor) { | |
| 256 } | |
| 257 | |
| 258 void WebContentsViewMus::OnWindowDestroying(aura::Window* window) {} | |
| 259 | |
| 260 void WebContentsViewMus::OnWindowDestroyed(aura::Window* window) {} | |
| 261 | |
| 262 void WebContentsViewMus::OnWindowTargetVisibilityChanged(bool visible) {} | |
| 263 | |
| 264 bool WebContentsViewMus::HasHitTestMask() const { | |
| 265 return false; | |
| 266 } | |
| 267 | |
| 268 void WebContentsViewMus::GetHitTestMask(gfx::Path* mask) const {} | |
| 269 | |
| 270 } // namespace content | |
| OLD | NEW |