| 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/tab_contents/tab_contents_view_win.h" | 5 #include "chrome/browser/tab_contents/tab_contents_view_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "app/gfx/canvas.h" | 9 #include "app/gfx/canvas.h" |
| 10 #include "app/os_exchange_data.h" | 10 #include "app/os_exchange_data.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 if (::IsWindow(GetNativeView())) | 225 if (::IsWindow(GetNativeView())) |
| 226 InvalidateRect(GetNativeView(), NULL, FALSE); | 226 InvalidateRect(GetNativeView(), NULL, FALSE); |
| 227 } | 227 } |
| 228 | 228 |
| 229 void TabContentsViewWin::SizeContents(const gfx::Size& size) { | 229 void TabContentsViewWin::SizeContents(const gfx::Size& size) { |
| 230 // TODO(brettw) this is a hack and should be removed. See tab_contents_view.h. | 230 // TODO(brettw) this is a hack and should be removed. See tab_contents_view.h. |
| 231 WasSized(size); | 231 WasSized(size); |
| 232 } | 232 } |
| 233 | 233 |
| 234 void TabContentsViewWin::Focus() { | 234 void TabContentsViewWin::Focus() { |
| 235 HWND container_hwnd = GetNativeView(); | 235 views::FocusManager* focus_manager = |
| 236 if (!container_hwnd) | 236 views::FocusManager::GetFocusManager(GetNativeView()); |
| 237 |
| 238 if (tab_contents()->interstitial_page()) { |
| 239 tab_contents()->interstitial_page()->Focus(); |
| 237 return; | 240 return; |
| 241 } |
| 238 | 242 |
| 239 views::FocusManager* focus_manager = | 243 if (sad_tab_.get()) { |
| 240 views::FocusManager::GetFocusManager(container_hwnd); | 244 sad_tab_->RequestFocus(); |
| 241 if (!focus_manager) | 245 return; |
| 242 return; // During testing we have no focus manager. | 246 } |
| 243 views::View* v = focus_manager->GetViewForWindow(container_hwnd, true); | 247 |
| 244 DCHECK(v); | 248 RenderWidgetHostView* rwhv = tab_contents()->render_widget_host_view(); |
| 245 if (v) | 249 if (rwhv) { |
| 246 v->RequestFocus(); | 250 ::SetFocus(rwhv->GetNativeView()); |
| 251 return; |
| 252 } |
| 253 |
| 254 // Default to focusing our HWND. |
| 255 ::SetFocus(GetNativeView()); |
| 247 } | 256 } |
| 248 | 257 |
| 249 void TabContentsViewWin::SetInitialFocus() { | 258 void TabContentsViewWin::SetInitialFocus() { |
| 250 if (tab_contents()->FocusLocationBarByDefault()) | 259 if (tab_contents()->FocusLocationBarByDefault()) |
| 251 tab_contents()->delegate()->SetFocusToLocationBar(); | 260 tab_contents()->delegate()->SetFocusToLocationBar(); |
| 252 else | 261 else |
| 253 ::SetFocus(GetNativeView()); | 262 Focus(); |
| 254 } | 263 } |
| 255 | 264 |
| 256 void TabContentsViewWin::StoreFocus() { | 265 void TabContentsViewWin::StoreFocus() { |
| 257 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); | 266 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); |
| 258 | 267 |
| 259 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) | 268 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) |
| 260 view_storage->RemoveView(last_focused_view_storage_id_); | 269 view_storage->RemoveView(last_focused_view_storage_id_); |
| 261 | 270 |
| 262 views::FocusManager* focus_manager = | 271 views::FocusManager* focus_manager = |
| 263 views::FocusManager::GetFocusManager(GetNativeView()); | 272 views::FocusManager::GetFocusManager(GetNativeView()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 SetInitialFocus(); | 318 SetInitialFocus(); |
| 310 } | 319 } |
| 311 view_storage->RemoveView(last_focused_view_storage_id_); | 320 view_storage->RemoveView(last_focused_view_storage_id_); |
| 312 } | 321 } |
| 313 } | 322 } |
| 314 | 323 |
| 315 void TabContentsViewWin::UpdateDragCursor(bool is_drop_target) { | 324 void TabContentsViewWin::UpdateDragCursor(bool is_drop_target) { |
| 316 drop_target_->set_is_drop_target(is_drop_target); | 325 drop_target_->set_is_drop_target(is_drop_target); |
| 317 } | 326 } |
| 318 | 327 |
| 328 void TabContentsViewWin::GotFocus() { |
| 329 tab_contents()->delegate()->TabContentsFocused(tab_contents()); |
| 330 } |
| 331 |
| 319 void TabContentsViewWin::TakeFocus(bool reverse) { | 332 void TabContentsViewWin::TakeFocus(bool reverse) { |
| 320 if (!tab_contents()->delegate()->TakeFocus(reverse)) { | 333 if (!tab_contents()->delegate()->TakeFocus(reverse)) { |
| 321 views::FocusManager* focus_manager = | 334 views::FocusManager* focus_manager = |
| 322 views::FocusManager::GetFocusManager(GetNativeView()); | 335 views::FocusManager::GetFocusManager(GetNativeView()); |
| 323 | 336 |
| 324 // We may not have a focus manager if the tab has been switched before this | 337 // We may not have a focus manager if the tab has been switched before this |
| 325 // message arrived. | 338 // message arrived. |
| 326 if (focus_manager) | 339 if (focus_manager) |
| 327 focus_manager->AdvanceFocus(reverse); | 340 focus_manager->AdvanceFocus(reverse); |
| 328 } | 341 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 case WM_VSCROLL: | 491 case WM_VSCROLL: |
| 479 if (ScrollZoom(LOWORD(message->wParam))) | 492 if (ScrollZoom(LOWORD(message->wParam))) |
| 480 return 1; | 493 return 1; |
| 481 default: | 494 default: |
| 482 break; | 495 break; |
| 483 } | 496 } |
| 484 | 497 |
| 485 return 0; | 498 return 0; |
| 486 } | 499 } |
| 487 | 500 |
| 488 void TabContentsViewWin::OnSetFocus(HWND window) { | |
| 489 // TODO(jcampan): figure out why removing this prevents tabs opened in the | |
| 490 // background from properly taking focus. | |
| 491 // We NULL-check the render_view_host_ here because Windows can send us | |
| 492 // messages during the destruction process after it has been destroyed. | |
| 493 if (tab_contents()->render_widget_host_view()) { | |
| 494 HWND inner_hwnd = | |
| 495 tab_contents()->render_widget_host_view()->GetNativeView(); | |
| 496 if (::IsWindow(inner_hwnd)) | |
| 497 ::SetFocus(inner_hwnd); | |
| 498 } | |
| 499 } | |
| 500 | |
| 501 void TabContentsViewWin::OnVScroll(int scroll_type, short position, | 501 void TabContentsViewWin::OnVScroll(int scroll_type, short position, |
| 502 HWND scrollbar) { | 502 HWND scrollbar) { |
| 503 ScrollCommon(WM_VSCROLL, scroll_type, position, scrollbar); | 503 ScrollCommon(WM_VSCROLL, scroll_type, position, scrollbar); |
| 504 } | 504 } |
| 505 | 505 |
| 506 void TabContentsViewWin::OnWindowPosChanged(WINDOWPOS* window_pos) { | 506 void TabContentsViewWin::OnWindowPosChanged(WINDOWPOS* window_pos) { |
| 507 if (window_pos->flags & SWP_HIDEWINDOW) { | 507 if (window_pos->flags & SWP_HIDEWINDOW) { |
| 508 WasHidden(); | 508 WasHidden(); |
| 509 } else { | 509 } else { |
| 510 // The TabContents was shown by a means other than the user selecting a | 510 // The TabContents was shown by a means other than the user selecting a |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 } | 612 } |
| 613 return false; | 613 return false; |
| 614 } | 614 } |
| 615 | 615 |
| 616 void TabContentsViewWin::WheelZoom(int distance) { | 616 void TabContentsViewWin::WheelZoom(int distance) { |
| 617 if (tab_contents()->delegate()) { | 617 if (tab_contents()->delegate()) { |
| 618 bool zoom_in = distance > 0; | 618 bool zoom_in = distance > 0; |
| 619 tab_contents()->delegate()->ContentsZoomChange(zoom_in); | 619 tab_contents()->delegate()->ContentsZoomChange(zoom_in); |
| 620 } | 620 } |
| 621 } | 621 } |
| OLD | NEW |