| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "views/view.h" | 5 #include "views/view.h" |
| 6 | 6 |
| 7 #include "app/drag_drop_types.h" | 7 #include "app/drag_drop_types.h" |
| 8 #include "app/gfx/canvas.h" | 8 #include "app/gfx/canvas.h" |
| 9 #include "app/gfx/path.h" | 9 #include "app/gfx/path.h" |
| 10 #include "app/os_exchange_data.h" | 10 #include "app/os_exchange_data.h" |
| 11 #include "base/scoped_handle.h" | 11 #include "base/scoped_handle.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "views/accessibility/view_accessibility_wrapper.h" | 13 #include "views/accessibility/view_accessibility_wrapper.h" |
| 14 #include "views/border.h" | 14 #include "views/border.h" |
| 15 #include "views/widget/root_view.h" | 15 #include "views/widget/root_view.h" |
| 16 #include "views/widget/widget.h" | 16 #include "views/widget/widget.h" |
| 17 | 17 |
| 18 namespace views { | 18 namespace views { |
| 19 | 19 |
| 20 FocusManager* View::GetFocusManager() { |
| 21 Widget* widget = GetWidget(); |
| 22 if (!widget) |
| 23 return NULL; |
| 24 |
| 25 HWND hwnd = widget->GetNativeView(); |
| 26 if (!hwnd) |
| 27 return NULL; |
| 28 |
| 29 return FocusManager::GetFocusManager(hwnd); |
| 30 } |
| 31 |
| 20 void View::DoDrag(const MouseEvent& e, int press_x, int press_y) { | 32 void View::DoDrag(const MouseEvent& e, int press_x, int press_y) { |
| 21 int drag_operations = GetDragOperations(press_x, press_y); | 33 int drag_operations = GetDragOperations(press_x, press_y); |
| 22 if (drag_operations == DragDropTypes::DRAG_NONE) | 34 if (drag_operations == DragDropTypes::DRAG_NONE) |
| 23 return; | 35 return; |
| 24 | 36 |
| 25 scoped_refptr<OSExchangeData> data = new OSExchangeData; | 37 scoped_refptr<OSExchangeData> data = new OSExchangeData; |
| 26 WriteDragData(press_x, press_y, data.get()); | 38 WriteDragData(press_x, press_y, data.get()); |
| 27 | 39 |
| 28 // Message the RootView to do the drag and drop. That way if we're removed | 40 // Message the RootView to do the drag and drop. That way if we're removed |
| 29 // the RootView can detect it and avoid calling us back. | 41 // the RootView can detect it and avoid calling us back. |
| 30 RootView* root_view = GetRootView(); | 42 RootView* root_view = GetRootView(); |
| 31 root_view->StartDragForViewFromMouseEvent(this, data, drag_operations); | 43 root_view->StartDragForViewFromMouseEvent(this, data, drag_operations); |
| 32 } | 44 } |
| 33 | 45 |
| 34 ViewAccessibilityWrapper* View::GetViewAccessibilityWrapper() { | 46 ViewAccessibilityWrapper* View::GetViewAccessibilityWrapper() { |
| 35 if (accessibility_.get() == NULL) { | 47 if (accessibility_.get() == NULL) { |
| 36 accessibility_.reset(new ViewAccessibilityWrapper(this)); | 48 accessibility_.reset(new ViewAccessibilityWrapper(this)); |
| 37 } | 49 } |
| 38 return accessibility_.get(); | 50 return accessibility_.get(); |
| 39 } | 51 } |
| 40 | 52 |
| 41 void View::Focus() { | 53 void View::Focus() { |
| 42 // Set the native focus to the root view window so it receives the keyboard | 54 // Set the native focus to the root view window so it receives the keyboard |
| 43 // messages. | 55 // messages. |
| 44 FocusManager* focus_manager = GetFocusManager(); | 56 FocusManager* focus_manager = GetFocusManager(); |
| 45 if (focus_manager) | 57 if (focus_manager) |
| 46 focus_manager->FocusNativeView(GetRootView()->GetWidget()->GetNativeView()); | 58 focus_manager->FocusHWND(GetRootView()->GetWidget()->GetNativeView()); |
| 47 } | 59 } |
| 48 | 60 |
| 49 int View::GetHorizontalDragThreshold() { | 61 int View::GetHorizontalDragThreshold() { |
| 50 static int threshold = -1; | 62 static int threshold = -1; |
| 51 if (threshold == -1) | 63 if (threshold == -1) |
| 52 threshold = GetSystemMetrics(SM_CXDRAG) / 2; | 64 threshold = GetSystemMetrics(SM_CXDRAG) / 2; |
| 53 return threshold; | 65 return threshold; |
| 54 } | 66 } |
| 55 | 67 |
| 56 int View::GetVerticalDragThreshold() { | 68 int View::GetVerticalDragThreshold() { |
| 57 static int threshold = -1; | 69 static int threshold = -1; |
| 58 if (threshold == -1) | 70 if (threshold == -1) |
| 59 threshold = GetSystemMetrics(SM_CYDRAG) / 2; | 71 threshold = GetSystemMetrics(SM_CYDRAG) / 2; |
| 60 return threshold; | 72 return threshold; |
| 61 } | 73 } |
| 62 | 74 |
| 63 } // namespace views | 75 } // namespace views |
| OLD | NEW |