OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/time.h" | 9 #include "base/time.h" |
10 #include "chrome/browser/download/download_request_limiter.h" | 10 #include "chrome/browser/download/download_request_limiter.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { | 34 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { |
35 return new TabContentsViewWin(tab_contents); | 35 return new TabContentsViewWin(tab_contents); |
36 } | 36 } |
37 | 37 |
38 TabContentsViewWin::TabContentsViewWin(TabContents* tab_contents) | 38 TabContentsViewWin::TabContentsViewWin(TabContents* tab_contents) |
39 : TabContentsView(tab_contents), | 39 : TabContentsView(tab_contents), |
40 focus_manager_(NULL), | 40 focus_manager_(NULL), |
41 close_tab_after_drag_ends_(false), | 41 close_tab_after_drag_ends_(false), |
42 sad_tab_(NULL) { | 42 sad_tab_(NULL) { |
43 last_focused_view_storage_id_ = | 43 last_focused_view_storage_id_ = |
44 views::ViewStorage::GetSharedInstance()->CreateStorageID(); | 44 views::ViewStorage::GetInstance()->CreateStorageID(); |
45 } | 45 } |
46 | 46 |
47 TabContentsViewWin::~TabContentsViewWin() { | 47 TabContentsViewWin::~TabContentsViewWin() { |
48 // Makes sure to remove any stored view we may still have in the ViewStorage. | 48 // Makes sure to remove any stored view we may still have in the ViewStorage. |
49 // | 49 // |
50 // It is possible the view went away before us, so we only do this if the | 50 // It is possible the view went away before us, so we only do this if the |
51 // view is registered. | 51 // view is registered. |
52 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); | 52 views::ViewStorage* view_storage = views::ViewStorage::GetInstance(); |
53 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) | 53 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) |
54 view_storage->RemoveView(last_focused_view_storage_id_); | 54 view_storage->RemoveView(last_focused_view_storage_id_); |
55 } | 55 } |
56 | 56 |
57 void TabContentsViewWin::Unparent() { | 57 void TabContentsViewWin::Unparent() { |
58 // Remember who our FocusManager is, we won't be able to access it once | 58 // Remember who our FocusManager is, we won't be able to access it once |
59 // unparented. | 59 // unparented. |
60 focus_manager_ = views::WidgetWin::GetFocusManager(); | 60 focus_manager_ = views::WidgetWin::GetFocusManager(); |
61 // Note that we do not DCHECK on focus_manager_ as it may be NULL when used | 61 // Note that we do not DCHECK on focus_manager_ as it may be NULL when used |
62 // with an external tab container. | 62 // with an external tab container. |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 } | 206 } |
207 | 207 |
208 void TabContentsViewWin::SetInitialFocus() { | 208 void TabContentsViewWin::SetInitialFocus() { |
209 if (tab_contents()->FocusLocationBarByDefault()) | 209 if (tab_contents()->FocusLocationBarByDefault()) |
210 tab_contents()->SetFocusToLocationBar(false); | 210 tab_contents()->SetFocusToLocationBar(false); |
211 else | 211 else |
212 Focus(); | 212 Focus(); |
213 } | 213 } |
214 | 214 |
215 void TabContentsViewWin::StoreFocus() { | 215 void TabContentsViewWin::StoreFocus() { |
216 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); | 216 views::ViewStorage* view_storage = views::ViewStorage::GetInstance(); |
217 | 217 |
218 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) | 218 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) |
219 view_storage->RemoveView(last_focused_view_storage_id_); | 219 view_storage->RemoveView(last_focused_view_storage_id_); |
220 | 220 |
221 views::FocusManager* focus_manager = | 221 views::FocusManager* focus_manager = |
222 views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); | 222 views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); |
223 if (focus_manager) { | 223 if (focus_manager) { |
224 // |focus_manager| can be NULL if the tab has been detached but still | 224 // |focus_manager| can be NULL if the tab has been detached but still |
225 // exists. | 225 // exists. |
226 views::View* focused_view = focus_manager->GetFocusedView(); | 226 views::View* focused_view = focus_manager->GetFocusedView(); |
227 if (focused_view) | 227 if (focused_view) |
228 view_storage->StoreView(last_focused_view_storage_id_, focused_view); | 228 view_storage->StoreView(last_focused_view_storage_id_, focused_view); |
229 | 229 |
230 // If the focus was on the page, explicitly clear the focus so that we | 230 // If the focus was on the page, explicitly clear the focus so that we |
231 // don't end up with the focused HWND not part of the window hierarchy. | 231 // don't end up with the focused HWND not part of the window hierarchy. |
232 // TODO(brettw) this should move to the view somehow. | 232 // TODO(brettw) this should move to the view somehow. |
233 HWND container_hwnd = GetNativeView(); | 233 HWND container_hwnd = GetNativeView(); |
234 if (container_hwnd) { | 234 if (container_hwnd) { |
235 views::View* focused_view = focus_manager->GetFocusedView(); | 235 views::View* focused_view = focus_manager->GetFocusedView(); |
236 if (focused_view) { | 236 if (focused_view) { |
237 HWND hwnd = focused_view->GetRootView()->GetWidget()->GetNativeView(); | 237 HWND hwnd = focused_view->GetRootView()->GetWidget()->GetNativeView(); |
238 if (container_hwnd == hwnd || ::IsChild(container_hwnd, hwnd)) | 238 if (container_hwnd == hwnd || ::IsChild(container_hwnd, hwnd)) |
239 focus_manager->ClearFocus(); | 239 focus_manager->ClearFocus(); |
240 } | 240 } |
241 } | 241 } |
242 } | 242 } |
243 } | 243 } |
244 | 244 |
245 void TabContentsViewWin::RestoreFocus() { | 245 void TabContentsViewWin::RestoreFocus() { |
246 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); | 246 views::ViewStorage* view_storage = views::ViewStorage::GetInstance(); |
247 views::View* last_focused_view = | 247 views::View* last_focused_view = |
248 view_storage->RetrieveView(last_focused_view_storage_id_); | 248 view_storage->RetrieveView(last_focused_view_storage_id_); |
249 | 249 |
250 if (!last_focused_view) { | 250 if (!last_focused_view) { |
251 SetInitialFocus(); | 251 SetInitialFocus(); |
252 } else { | 252 } else { |
253 views::FocusManager* focus_manager = | 253 views::FocusManager* focus_manager = |
254 views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); | 254 views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); |
255 | 255 |
256 // If you hit this DCHECK, please report it to Jay (jcampan). | 256 // If you hit this DCHECK, please report it to Jay (jcampan). |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 } | 567 } |
568 return false; | 568 return false; |
569 } | 569 } |
570 | 570 |
571 void TabContentsViewWin::WheelZoom(int distance) { | 571 void TabContentsViewWin::WheelZoom(int distance) { |
572 if (tab_contents()->delegate()) { | 572 if (tab_contents()->delegate()) { |
573 bool zoom_in = distance > 0; | 573 bool zoom_in = distance > 0; |
574 tab_contents()->delegate()->ContentsZoomChange(zoom_in); | 574 tab_contents()->delegate()->ContentsZoomChange(zoom_in); |
575 } | 575 } |
576 } | 576 } |
OLD | NEW |