Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: chrome/browser/views/tab_contents/tab_contents_view_win.cc

Issue 141013: Relanding focus manager refactoring (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); 66 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance();
67 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) 67 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL)
68 view_storage->RemoveView(last_focused_view_storage_id_); 68 view_storage->RemoveView(last_focused_view_storage_id_);
69 } 69 }
70 70
71 void TabContentsViewWin::CreateView() { 71 void TabContentsViewWin::CreateView() {
72 set_delete_on_destroy(false); 72 set_delete_on_destroy(false);
73 // Since we create these windows parented to the desktop window initially, we 73 // Since we create these windows parented to the desktop window initially, we
74 // don't want to create them initially visible. 74 // don't want to create them initially visible.
75 set_window_style(WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); 75 set_window_style(WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
76 WidgetWin::Init(GetDesktopWindow(), gfx::Rect(), false); 76 WidgetWin::Init(GetDesktopWindow(), gfx::Rect());
77 77
78 // Remove the root view drop target so we can register our own. 78 // Remove the root view drop target so we can register our own.
79 RevokeDragDrop(GetNativeView()); 79 RevokeDragDrop(GetNativeView());
80 drop_target_ = new WebDropTarget(GetNativeView(), tab_contents()); 80 drop_target_ = new WebDropTarget(GetNativeView(), tab_contents());
81 } 81 }
82 82
83 RenderWidgetHostView* TabContentsViewWin::CreateViewForWidget( 83 RenderWidgetHostView* TabContentsViewWin::CreateViewForWidget(
84 RenderWidgetHost* render_widget_host) { 84 RenderWidgetHost* render_widget_host) {
85 if (render_widget_host->view()) { 85 if (render_widget_host->view()) {
86 // During testing, the view will already be set up in most cases to the 86 // During testing, the view will already be set up in most cases to the
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 views::FocusManager* focus_manager = 235 views::FocusManager* focus_manager =
236 views::FocusManager::GetFocusManager(GetNativeView()); 236 views::FocusManager::GetFocusManagerForNativeView(GetNativeView());
237 237
238 if (tab_contents()->interstitial_page()) { 238 if (tab_contents()->interstitial_page()) {
239 tab_contents()->interstitial_page()->Focus(); 239 tab_contents()->interstitial_page()->Focus();
240 return; 240 return;
241 } 241 }
242 242
243 if (sad_tab_.get()) { 243 if (sad_tab_.get()) {
244 sad_tab_->RequestFocus(); 244 sad_tab_->RequestFocus();
245 return; 245 return;
246 } 246 }
(...skipping 15 matching lines...) Expand all
262 Focus(); 262 Focus();
263 } 263 }
264 264
265 void TabContentsViewWin::StoreFocus() { 265 void TabContentsViewWin::StoreFocus() {
266 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); 266 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance();
267 267
268 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) 268 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL)
269 view_storage->RemoveView(last_focused_view_storage_id_); 269 view_storage->RemoveView(last_focused_view_storage_id_);
270 270
271 views::FocusManager* focus_manager = 271 views::FocusManager* focus_manager =
272 views::FocusManager::GetFocusManager(GetNativeView()); 272 views::FocusManager::GetFocusManagerForNativeView(GetNativeView());
273 if (focus_manager) { 273 if (focus_manager) {
274 // |focus_manager| can be NULL if the tab has been detached but still 274 // |focus_manager| can be NULL if the tab has been detached but still
275 // exists. 275 // exists.
276 views::View* focused_view = focus_manager->GetFocusedView(); 276 views::View* focused_view = focus_manager->GetFocusedView();
277 if (focused_view) 277 if (focused_view)
278 view_storage->StoreView(last_focused_view_storage_id_, focused_view); 278 view_storage->StoreView(last_focused_view_storage_id_, focused_view);
279 279
280 // If the focus was on the page, explicitly clear the focus so that we 280 // If the focus was on the page, explicitly clear the focus so that we
281 // don't end up with the focused HWND not part of the window hierarchy. 281 // don't end up with the focused HWND not part of the window hierarchy.
282 // TODO(brettw) this should move to the view somehow. 282 // TODO(brettw) this should move to the view somehow.
(...skipping 11 matching lines...) Expand all
294 294
295 void TabContentsViewWin::RestoreFocus() { 295 void TabContentsViewWin::RestoreFocus() {
296 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); 296 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance();
297 views::View* last_focused_view = 297 views::View* last_focused_view =
298 view_storage->RetrieveView(last_focused_view_storage_id_); 298 view_storage->RetrieveView(last_focused_view_storage_id_);
299 299
300 if (!last_focused_view) { 300 if (!last_focused_view) {
301 SetInitialFocus(); 301 SetInitialFocus();
302 } else { 302 } else {
303 views::FocusManager* focus_manager = 303 views::FocusManager* focus_manager =
304 views::FocusManager::GetFocusManager(GetNativeView()); 304 views::FocusManager::GetFocusManagerForNativeView(GetNativeView());
305 305
306 // If you hit this DCHECK, please report it to Jay (jcampan). 306 // If you hit this DCHECK, please report it to Jay (jcampan).
307 DCHECK(focus_manager != NULL) << "No focus manager when restoring focus."; 307 DCHECK(focus_manager != NULL) << "No focus manager when restoring focus.";
308 308
309 if (last_focused_view->IsFocusable() && focus_manager && 309 if (last_focused_view->IsFocusable() && focus_manager &&
310 focus_manager->ContainsView(last_focused_view)) { 310 focus_manager->ContainsView(last_focused_view)) {
311 last_focused_view->RequestFocus(); 311 last_focused_view->RequestFocus();
312 } else { 312 } else {
313 // The focused view may not belong to the same window hierarchy (e.g. 313 // The focused view may not belong to the same window hierarchy (e.g.
314 // if the location bar was focused and the tab is dragged out), or it may 314 // if the location bar was focused and the tab is dragged out), or it may
(...skipping 11 matching lines...) Expand all
326 } 326 }
327 327
328 void TabContentsViewWin::GotFocus() { 328 void TabContentsViewWin::GotFocus() {
329 if (tab_contents()->delegate()) 329 if (tab_contents()->delegate())
330 tab_contents()->delegate()->TabContentsFocused(tab_contents()); 330 tab_contents()->delegate()->TabContentsFocused(tab_contents());
331 } 331 }
332 332
333 void TabContentsViewWin::TakeFocus(bool reverse) { 333 void TabContentsViewWin::TakeFocus(bool reverse) {
334 if (!tab_contents()->delegate()->TakeFocus(reverse)) { 334 if (!tab_contents()->delegate()->TakeFocus(reverse)) {
335 views::FocusManager* focus_manager = 335 views::FocusManager* focus_manager =
336 views::FocusManager::GetFocusManager(GetNativeView()); 336 views::FocusManager::GetFocusManagerForNativeView(GetNativeView());
337 337
338 // We may not have a focus manager if the tab has been switched before this 338 // We may not have a focus manager if the tab has been switched before this
339 // message arrived. 339 // message arrived.
340 if (focus_manager) 340 if (focus_manager)
341 focus_manager->AdvanceFocus(reverse); 341 focus_manager->AdvanceFocus(reverse);
342 } 342 }
343 } 343 }
344 344
345 void TabContentsViewWin::HandleKeyboardEvent( 345 void TabContentsViewWin::HandleKeyboardEvent(
346 const NativeWebKeyboardEvent& event) { 346 const NativeWebKeyboardEvent& event) {
347 // Previous calls to TranslateMessage can generate CHAR events as well as 347 // Previous calls to TranslateMessage can generate CHAR events as well as
348 // RAW_KEY_DOWN events, even if the latter triggered an accelerator. In these 348 // RAW_KEY_DOWN events, even if the latter triggered an accelerator. In these
349 // cases, we discard the CHAR events. 349 // cases, we discard the CHAR events.
350 if (event.type == WebInputEvent::Char && ignore_next_char_event_) { 350 if (event.type == WebInputEvent::Char && ignore_next_char_event_) {
351 ignore_next_char_event_ = false; 351 ignore_next_char_event_ = false;
352 return; 352 return;
353 } 353 }
354 ignore_next_char_event_ = false; 354 ignore_next_char_event_ = false;
355 355
356 // The renderer returned a keyboard event it did not process. This may be 356 // The renderer returned a keyboard event it did not process. This may be
357 // a keyboard shortcut that we have to process. 357 // a keyboard shortcut that we have to process.
358 if (event.type == WebInputEvent::RawKeyDown) { 358 if (event.type == WebInputEvent::RawKeyDown) {
359 views::FocusManager* focus_manager = 359 views::FocusManager* focus_manager =
360 views::FocusManager::GetFocusManager(GetNativeView()); 360 views::FocusManager::GetFocusManagerForNativeView(GetNativeView());
361 // We may not have a focus_manager at this point (if the tab has been 361 // We may not have a focus_manager at this point (if the tab has been
362 // switched by the time this message returned). 362 // switched by the time this message returned).
363 if (focus_manager) { 363 if (focus_manager) {
364 views::Accelerator accelerator(event.windowsKeyCode, 364 views::Accelerator accelerator(event.windowsKeyCode,
365 (event.modifiers & WebInputEvent::ShiftKey) == 365 (event.modifiers & WebInputEvent::ShiftKey) ==
366 WebInputEvent::ShiftKey, 366 WebInputEvent::ShiftKey,
367 (event.modifiers & WebInputEvent::ControlKey) == 367 (event.modifiers & WebInputEvent::ControlKey) ==
368 WebInputEvent::ControlKey, 368 WebInputEvent::ControlKey,
369 (event.modifiers & WebInputEvent::AltKey) == 369 (event.modifiers & WebInputEvent::AltKey) ==
370 WebInputEvent::AltKey); 370 WebInputEvent::AltKey);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 } 609 }
610 return false; 610 return false;
611 } 611 }
612 612
613 void TabContentsViewWin::WheelZoom(int distance) { 613 void TabContentsViewWin::WheelZoom(int distance) {
614 if (tab_contents()->delegate()) { 614 if (tab_contents()->delegate()) {
615 bool zoom_in = distance > 0; 615 bool zoom_in = distance > 0;
616 tab_contents()->delegate()->ContentsZoomChange(zoom_in); 616 tab_contents()->delegate()->ContentsZoomChange(zoom_in);
617 } 617 }
618 } 618 }
OLDNEW
« no previous file with comments | « chrome/browser/views/status_bubble_views.cc ('k') | chrome/browser/views/tabs/dragged_tab_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698