| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/web_contents/web_contents_view_win.h" | 5 #include "content/browser/web_contents/web_contents_view_win.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "content/browser/renderer_host/render_view_host_factory.h" | 9 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 10 #include "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace namespace | 95 } // namespace namespace |
| 96 | 96 |
| 97 WebContentsViewWin::WebContentsViewWin(WebContentsImpl* web_contents, | 97 WebContentsViewWin::WebContentsViewWin(WebContentsImpl* web_contents, |
| 98 WebContentsViewDelegate* delegate) | 98 WebContentsViewDelegate* delegate) |
| 99 : web_contents_(web_contents), | 99 : web_contents_(web_contents), |
| 100 view_(NULL), | 100 view_(NULL), |
| 101 delegate_(delegate), | 101 delegate_(delegate), |
| 102 close_tab_after_drag_ends_(false), | |
| 103 hwnd_message_filter_(new PositionChangedMessageFilter) { | 102 hwnd_message_filter_(new PositionChangedMessageFilter) { |
| 104 } | 103 } |
| 105 | 104 |
| 106 WebContentsViewWin::~WebContentsViewWin() { | 105 WebContentsViewWin::~WebContentsViewWin() { |
| 107 RemoveHwndToWcvMapEntry(this); | 106 RemoveHwndToWcvMapEntry(this); |
| 108 | 107 |
| 109 if (IsWindow(hwnd())) | 108 if (IsWindow(hwnd())) |
| 110 DestroyWindow(hwnd()); | 109 DestroyWindow(hwnd()); |
| 111 } | 110 } |
| 112 | 111 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 void WebContentsViewWin::StoreFocus() { | 225 void WebContentsViewWin::StoreFocus() { |
| 227 if (delegate_.get()) | 226 if (delegate_.get()) |
| 228 delegate_->StoreFocus(); | 227 delegate_->StoreFocus(); |
| 229 } | 228 } |
| 230 | 229 |
| 231 void WebContentsViewWin::RestoreFocus() { | 230 void WebContentsViewWin::RestoreFocus() { |
| 232 if (delegate_.get()) | 231 if (delegate_.get()) |
| 233 delegate_->RestoreFocus(); | 232 delegate_->RestoreFocus(); |
| 234 } | 233 } |
| 235 | 234 |
| 236 bool WebContentsViewWin::IsDoingDrag() const { | |
| 237 return drag_handler_.get() != NULL; | |
| 238 } | |
| 239 | |
| 240 void WebContentsViewWin::CancelDragAndCloseTab() { | |
| 241 DCHECK(IsDoingDrag()); | |
| 242 // We can't close the tab while we're in the drag and | |
| 243 // |drag_handler_->CancelDrag()| is async. Instead, set a flag to cancel | |
| 244 // the drag and when the drag nested message loop ends, close the tab. | |
| 245 drag_handler_->CancelDrag(); | |
| 246 close_tab_after_drag_ends_ = true; | |
| 247 } | |
| 248 | |
| 249 WebDropData* WebContentsViewWin::GetDropData() const { | 235 WebDropData* WebContentsViewWin::GetDropData() const { |
| 250 return drag_dest_->current_drop_data(); | 236 return drag_dest_->current_drop_data(); |
| 251 } | 237 } |
| 252 | 238 |
| 253 bool WebContentsViewWin::IsEventTracking() const { | 239 bool WebContentsViewWin::IsEventTracking() const { |
| 254 return false; | 240 return false; |
| 255 } | 241 } |
| 256 | 242 |
| 257 void WebContentsViewWin::CloseTabAfterEventTracking() { | 243 void WebContentsViewWin::CloseTabAfterEventTracking() { |
| 258 } | 244 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 void WebContentsViewWin::TakeFocus(bool reverse) { | 291 void WebContentsViewWin::TakeFocus(bool reverse) { |
| 306 if (web_contents_->GetDelegate() && | 292 if (web_contents_->GetDelegate() && |
| 307 !web_contents_->GetDelegate()->TakeFocus(web_contents_, reverse) && | 293 !web_contents_->GetDelegate()->TakeFocus(web_contents_, reverse) && |
| 308 delegate_.get()) { | 294 delegate_.get()) { |
| 309 delegate_->TakeFocus(reverse); | 295 delegate_->TakeFocus(reverse); |
| 310 } | 296 } |
| 311 } | 297 } |
| 312 | 298 |
| 313 void WebContentsViewWin::EndDragging() { | 299 void WebContentsViewWin::EndDragging() { |
| 314 drag_handler_ = NULL; | 300 drag_handler_ = NULL; |
| 315 if (close_tab_after_drag_ends_) { | |
| 316 close_tab_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(0), | |
| 317 this, &WebContentsViewWin::CloseTab); | |
| 318 } | |
| 319 web_contents_->SystemDragEnded(); | 301 web_contents_->SystemDragEnded(); |
| 320 } | 302 } |
| 321 | 303 |
| 322 void WebContentsViewWin::CloseTab() { | 304 void WebContentsViewWin::CloseTab() { |
| 323 RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | 305 RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
| 324 rvh->GetDelegate()->Close(rvh); | 306 rvh->GetDelegate()->Close(rvh); |
| 325 } | 307 } |
| 326 | 308 |
| 327 LRESULT WebContentsViewWin::OnCreate( | 309 LRESULT WebContentsViewWin::OnCreate( |
| 328 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { | 310 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { |
| 329 hwnd_to_wcv_map.insert(std::make_pair(hwnd(), this)); | 311 hwnd_to_wcv_map.insert(std::make_pair(hwnd(), this)); |
| 330 AddFilterToParentHwndSubclass(hwnd(), hwnd_message_filter_.get()); | 312 AddFilterToParentHwndSubclass(hwnd(), hwnd_message_filter_.get()); |
| 331 return 0; | 313 return 0; |
| 332 } | 314 } |
| 333 | 315 |
| 334 LRESULT WebContentsViewWin::OnDestroy( | 316 LRESULT WebContentsViewWin::OnDestroy( |
| 335 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { | 317 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { |
| 336 if (drag_dest_.get()) { | 318 if (drag_dest_.get()) { |
| 337 RevokeDragDrop(GetNativeView()); | 319 RevokeDragDrop(GetNativeView()); |
| 338 drag_dest_ = NULL; | 320 drag_dest_ = NULL; |
| 339 } | 321 } |
| 322 if (drag_handler_.get()) { |
| 323 drag_handler_->CancelDrag(); |
| 324 drag_handler_ = NULL; |
| 325 } |
| 340 return 0; | 326 return 0; |
| 341 } | 327 } |
| 342 | 328 |
| 343 LRESULT WebContentsViewWin::OnWindowPosChanged( | 329 LRESULT WebContentsViewWin::OnWindowPosChanged( |
| 344 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { | 330 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { |
| 345 | 331 |
| 346 // Our parent might have changed. So we re-install our hwnd message filter. | 332 // Our parent might have changed. So we re-install our hwnd message filter. |
| 347 AddFilterToParentHwndSubclass(hwnd(), hwnd_message_filter_.get()); | 333 AddFilterToParentHwndSubclass(hwnd(), hwnd_message_filter_.get()); |
| 348 | 334 |
| 349 WINDOWPOS* window_pos = reinterpret_cast<WINDOWPOS*>(lparam); | 335 WINDOWPOS* window_pos = reinterpret_cast<WINDOWPOS*>(lparam); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 si.nMin = 1; | 474 si.nMin = 1; |
| 489 si.nMax = 100; | 475 si.nMax = 100; |
| 490 si.nPage = 10; | 476 si.nPage = 10; |
| 491 si.nPos = 50; | 477 si.nPos = 50; |
| 492 | 478 |
| 493 ::SetScrollInfo(hwnd(), SB_HORZ, &si, FALSE); | 479 ::SetScrollInfo(hwnd(), SB_HORZ, &si, FALSE); |
| 494 ::SetScrollInfo(hwnd(), SB_VERT, &si, FALSE); | 480 ::SetScrollInfo(hwnd(), SB_VERT, &si, FALSE); |
| 495 | 481 |
| 496 return 1; | 482 return 1; |
| 497 } | 483 } |
| OLD | NEW |