OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/views/tab_contents/tab_contents_view_win.h" | 5 #include "chrome/browser/views/tab_contents/tab_contents_view_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "app/gfx/canvas_paint.h" | 9 #include "app/gfx/canvas_paint.h" |
10 #include "app/os_exchange_data.h" | 10 #include "app/os_exchange_data.h" |
| 11 #include "base/time.h" |
11 #include "chrome/browser/bookmarks/bookmark_drag_data.h" | 12 #include "chrome/browser/bookmarks/bookmark_drag_data.h" |
12 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful. | 13 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful. |
13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/download/download_request_manager.h" | 15 #include "chrome/browser/download/download_request_manager.h" |
15 #include "chrome/browser/renderer_host/render_process_host.h" | 16 #include "chrome/browser/renderer_host/render_process_host.h" |
16 #include "chrome/browser/renderer_host/render_view_host.h" | 17 #include "chrome/browser/renderer_host/render_view_host.h" |
17 #include "chrome/browser/renderer_host/render_view_host_factory.h" | 18 #include "chrome/browser/renderer_host/render_view_host_factory.h" |
18 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" | 19 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" |
19 #include "chrome/browser/tab_contents/interstitial_page.h" | 20 #include "chrome/browser/tab_contents/interstitial_page.h" |
20 #include "chrome/browser/tab_contents/tab_contents.h" | 21 #include "chrome/browser/tab_contents/tab_contents.h" |
(...skipping 26 matching lines...) Expand all Loading... |
47 } // namespace | 48 } // namespace |
48 | 49 |
49 // static | 50 // static |
50 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { | 51 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { |
51 return new TabContentsViewWin(tab_contents); | 52 return new TabContentsViewWin(tab_contents); |
52 } | 53 } |
53 | 54 |
54 TabContentsViewWin::TabContentsViewWin(TabContents* tab_contents) | 55 TabContentsViewWin::TabContentsViewWin(TabContents* tab_contents) |
55 : TabContentsView(tab_contents), | 56 : TabContentsView(tab_contents), |
56 ignore_next_char_event_(false), | 57 ignore_next_char_event_(false), |
57 focus_manager_(NULL) { | 58 focus_manager_(NULL), |
| 59 close_tab_after_drag_ends_(false) { |
58 last_focused_view_storage_id_ = | 60 last_focused_view_storage_id_ = |
59 views::ViewStorage::GetSharedInstance()->CreateStorageID(); | 61 views::ViewStorage::GetSharedInstance()->CreateStorageID(); |
60 } | 62 } |
61 | 63 |
62 TabContentsViewWin::~TabContentsViewWin() { | 64 TabContentsViewWin::~TabContentsViewWin() { |
63 // Makes sure to remove any stored view we may still have in the ViewStorage. | 65 // Makes sure to remove any stored view we may still have in the ViewStorage. |
64 // | 66 // |
65 // It is possible the view went away before us, so we only do this if the | 67 // It is possible the view went away before us, so we only do this if the |
66 // view is registered. | 68 // view is registered. |
67 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); | 69 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); |
68 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) | 70 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) |
69 view_storage->RemoveView(last_focused_view_storage_id_); | 71 view_storage->RemoveView(last_focused_view_storage_id_); |
| 72 |
| 73 DCHECK(!drag_source_.get()); |
70 } | 74 } |
71 | 75 |
72 void TabContentsViewWin::Unparent() { | 76 void TabContentsViewWin::Unparent() { |
73 // Remember who our FocusManager is, we won't be able to access it once | 77 // Remember who our FocusManager is, we won't be able to access it once |
74 // unparented. | 78 // unparented. |
75 focus_manager_ = views::WidgetWin::GetFocusManager(); | 79 focus_manager_ = views::WidgetWin::GetFocusManager(); |
76 // Note that we do not DCHECK on focus_manager_ as it may be NULL when used | 80 // Note that we do not DCHECK on focus_manager_ as it may be NULL when used |
77 // with an external tab container. | 81 // with an external tab container. |
78 ::SetParent(GetNativeView(), NULL); | 82 ::SetParent(GetNativeView(), NULL); |
79 } | 83 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 // Pass in NULL as the profile so that the bookmark always adds the url | 171 // Pass in NULL as the profile so that the bookmark always adds the url |
168 // rather than trying to move an existing url. | 172 // rather than trying to move an existing url. |
169 bm_drag_data.Write(NULL, data); | 173 bm_drag_data.Write(NULL, data); |
170 } else { | 174 } else { |
171 data->SetURL(drop_data.url, drop_data.url_title); | 175 data->SetURL(drop_data.url, drop_data.url_title); |
172 } | 176 } |
173 } | 177 } |
174 if (!drop_data.plain_text.empty()) | 178 if (!drop_data.plain_text.empty()) |
175 data->SetString(drop_data.plain_text); | 179 data->SetString(drop_data.plain_text); |
176 | 180 |
177 scoped_refptr<WebDragSource> drag_source( | 181 drag_source_ = new WebDragSource(GetNativeView(), |
178 new WebDragSource(GetNativeView(), tab_contents()->render_view_host())); | 182 tab_contents()->render_view_host()); |
179 | 183 |
180 DWORD effects; | 184 DWORD effects; |
181 | 185 |
182 // We need to enable recursive tasks on the message loop so we can get | 186 // We need to enable recursive tasks on the message loop so we can get |
183 // updates while in the system DoDragDrop loop. | 187 // updates while in the system DoDragDrop loop. |
184 bool old_state = MessageLoop::current()->NestableTasksAllowed(); | 188 bool old_state = MessageLoop::current()->NestableTasksAllowed(); |
185 MessageLoop::current()->SetNestableTasksAllowed(true); | 189 MessageLoop::current()->SetNestableTasksAllowed(true); |
186 DoDragDrop(data, drag_source, DROPEFFECT_COPY | DROPEFFECT_LINK, &effects); | 190 DoDragDrop(data, drag_source_, DROPEFFECT_COPY | DROPEFFECT_LINK, &effects); |
187 MessageLoop::current()->SetNestableTasksAllowed(old_state); | 191 MessageLoop::current()->SetNestableTasksAllowed(old_state); |
188 | 192 |
| 193 drag_source_ = NULL; |
| 194 if (close_tab_after_drag_ends_) { |
| 195 close_tab_timer_.Start(base::TimeDelta::FromMilliseconds(0), this, |
| 196 &TabContentsViewWin::CloseTab); |
| 197 } |
| 198 |
189 if (tab_contents()->render_view_host()) | 199 if (tab_contents()->render_view_host()) |
190 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); | 200 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); |
191 } | 201 } |
192 | 202 |
193 void TabContentsViewWin::OnContentsDestroy() { | 203 void TabContentsViewWin::OnContentsDestroy() { |
194 // TODO(brettw) this seems like maybe it can be moved into OnDestroy and this | 204 // TODO(brettw) this seems like maybe it can be moved into OnDestroy and this |
195 // function can be deleted? If you're adding more here, consider whether it | 205 // function can be deleted? If you're adding more here, consider whether it |
196 // can be moved into OnDestroy which is a Windows message handler as the | 206 // can be moved into OnDestroy which is a Windows message handler as the |
197 // window is being torn down. | 207 // window is being torn down. |
198 | 208 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 // if the location bar was focused and the tab is dragged out), or it may | 337 // if the location bar was focused and the tab is dragged out), or it may |
328 // no longer be focusable (e.g. if the location bar was focused and then | 338 // no longer be focusable (e.g. if the location bar was focused and then |
329 // we switched to fullscreen mode). In that case we default to the | 339 // we switched to fullscreen mode). In that case we default to the |
330 // default focus. | 340 // default focus. |
331 SetInitialFocus(); | 341 SetInitialFocus(); |
332 } | 342 } |
333 view_storage->RemoveView(last_focused_view_storage_id_); | 343 view_storage->RemoveView(last_focused_view_storage_id_); |
334 } | 344 } |
335 } | 345 } |
336 | 346 |
| 347 bool TabContentsViewWin::IsDoingDrag() const { |
| 348 return drag_source_.get() != NULL; |
| 349 } |
| 350 |
| 351 void TabContentsViewWin::CancelDragAndCloseTab() { |
| 352 DCHECK(IsDoingDrag()); |
| 353 // We can't close the tab while we're in the drag and |
| 354 // |drag_source_->CancelDrag()| is async. Instead, set a flag to cancel |
| 355 // the drag and when the drag nested message loop ends, close the tab. |
| 356 drag_source_->CancelDrag(); |
| 357 close_tab_after_drag_ends_ = true; |
| 358 } |
| 359 |
337 void TabContentsViewWin::UpdateDragCursor(bool is_drop_target) { | 360 void TabContentsViewWin::UpdateDragCursor(bool is_drop_target) { |
338 drop_target_->set_is_drop_target(is_drop_target); | 361 drop_target_->set_is_drop_target(is_drop_target); |
339 } | 362 } |
340 | 363 |
341 void TabContentsViewWin::GotFocus() { | 364 void TabContentsViewWin::GotFocus() { |
342 if (tab_contents()->delegate()) | 365 if (tab_contents()->delegate()) |
343 tab_contents()->delegate()->TabContentsFocused(tab_contents()); | 366 tab_contents()->delegate()->TabContentsFocused(tab_contents()); |
344 } | 367 } |
345 | 368 |
346 void TabContentsViewWin::TakeFocus(bool reverse) { | 369 void TabContentsViewWin::TakeFocus(bool reverse) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 return focus_manager; | 438 return focus_manager; |
416 } | 439 } |
417 // TODO(jcampan): we should DCHECK on focus_manager_, as it should not be | 440 // TODO(jcampan): we should DCHECK on focus_manager_, as it should not be |
418 // NULL. We are not doing it as it breaks some unit-tests. We should | 441 // NULL. We are not doing it as it breaks some unit-tests. We should |
419 // probably have an empty TabContentView implementation for the unit-tests, | 442 // probably have an empty TabContentView implementation for the unit-tests, |
420 // that would prevent that code being executed in the unit-test case. | 443 // that would prevent that code being executed in the unit-test case. |
421 // DCHECK(focus_manager_); | 444 // DCHECK(focus_manager_); |
422 return focus_manager_; | 445 return focus_manager_; |
423 } | 446 } |
424 | 447 |
| 448 void TabContentsViewWin::CloseTab() { |
| 449 tab_contents()->Close(tab_contents()->render_view_host()); |
| 450 } |
| 451 |
425 void TabContentsViewWin::ShowContextMenu(const ContextMenuParams& params) { | 452 void TabContentsViewWin::ShowContextMenu(const ContextMenuParams& params) { |
426 // Allow delegates to handle the context menu operation first. | 453 // Allow delegates to handle the context menu operation first. |
427 if (tab_contents()->delegate()->HandleContextMenu(params)) | 454 if (tab_contents()->delegate()->HandleContextMenu(params)) |
428 return; | 455 return; |
429 | 456 |
430 context_menu_.reset(new RenderViewContextMenuWin(tab_contents(), params)); | 457 context_menu_.reset(new RenderViewContextMenuWin(tab_contents(), params)); |
431 context_menu_->Init(); | 458 context_menu_->Init(); |
432 | 459 |
433 POINT screen_pt = { params.x, params.y }; | 460 POINT screen_pt = { params.x, params.y }; |
434 MapWindowPoints(GetNativeView(), HWND_DESKTOP, &screen_pt, 1); | 461 MapWindowPoints(GetNativeView(), HWND_DESKTOP, &screen_pt, 1); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 } | 665 } |
639 return false; | 666 return false; |
640 } | 667 } |
641 | 668 |
642 void TabContentsViewWin::WheelZoom(int distance) { | 669 void TabContentsViewWin::WheelZoom(int distance) { |
643 if (tab_contents()->delegate()) { | 670 if (tab_contents()->delegate()) { |
644 bool zoom_in = distance > 0; | 671 bool zoom_in = distance > 0; |
645 tab_contents()->delegate()->ContentsZoomChange(zoom_in); | 672 tab_contents()->delegate()->ContentsZoomChange(zoom_in); |
646 } | 673 } |
647 } | 674 } |
OLD | NEW |