| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/ui_controls/ui_controls.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 |
| 9 namespace ui_controls { |
| 10 |
| 11 namespace { |
| 12 |
| 13 UIControls* g_ui_controls[UI_CONTROLS_TYPE_LAST + 1] = { 0 }; |
| 14 UIControlsTypeDelegate* g_ui_controls_type_delegate = NULL; |
| 15 |
| 16 } // namespace |
| 17 |
| 18 UIControls::UIControls() { |
| 19 } |
| 20 |
| 21 UIControls::~UIControls() { |
| 22 } |
| 23 |
| 24 // static |
| 25 UIControls* UIControls::GetUIControlsFor(gfx::NativeView view) { |
| 26 UIControlsType type = UI_CONTROLS_TYPE_NATIVE; |
| 27 if (g_ui_controls_type_delegate) |
| 28 type = g_ui_controls_type_delegate->GetUIControlsTypeForNativeView(view); |
| 29 if (type == UI_CONTROLS_TYPE_NATIVE) |
| 30 return GetNativeUIControls(); |
| 31 DCHECK(g_ui_controls[type]); |
| 32 return g_ui_controls[type]; |
| 33 } |
| 34 |
| 35 // static |
| 36 void UIControls::SetUIControlsInstance( |
| 37 UIControlsType type, UIControls* instance) { |
| 38 DCHECK_LE(type, UI_CONTROLS_TYPE_LAST); |
| 39 delete g_ui_controls[type]; |
| 40 g_ui_controls[type] = instance; |
| 41 } |
| 42 |
| 43 // static |
| 44 UIControls* UIControls::GetUIControlsByType(UIControlsType type) { |
| 45 return g_ui_controls[type]; |
| 46 } |
| 47 |
| 48 // static |
| 49 void UIControls::SetUIControlsTypeDelegate(UIControlsTypeDelegate* delegate) { |
| 50 g_ui_controls_type_delegate = delegate; |
| 51 } |
| 52 |
| 53 // static |
| 54 UIControls* UIControls::GetNativeUIControls() { |
| 55 if (!g_ui_controls[UI_CONTROLS_TYPE_NATIVE]) |
| 56 g_ui_controls[UI_CONTROLS_TYPE_NATIVE] = CreateNativeUIControls(); |
| 57 return g_ui_controls[UI_CONTROLS_TYPE_NATIVE]; |
| 58 } |
| 59 |
| 60 |
| 61 // ALL OF THESE ARE DEPRECATED, SEE HEADER. http://crbug.com/128578 |
| 62 bool SendKeyPress(gfx::NativeWindow window, |
| 63 ui::KeyboardCode key, |
| 64 bool control, |
| 65 bool shift, |
| 66 bool alt, |
| 67 bool command) { |
| 68 return UIControls::GetNativeUIControls()->SendKeyPress( |
| 69 window, key, control, shift, alt, command); |
| 70 } |
| 71 |
| 72 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, |
| 73 ui::KeyboardCode key, |
| 74 bool control, |
| 75 bool shift, |
| 76 bool alt, |
| 77 bool command, |
| 78 const base::Closure& task) { |
| 79 return UIControls::GetNativeUIControls()->SendKeyPressNotifyWhenDone( |
| 80 window, key, control, shift, alt, command, task); |
| 81 } |
| 82 |
| 83 bool SendMouseMove(long x, long y) { |
| 84 return UIControls::GetNativeUIControls()->SendMouseMove(x, y); |
| 85 } |
| 86 |
| 87 bool SendMouseMoveNotifyWhenDone(long x, |
| 88 long y, |
| 89 const base::Closure& task) { |
| 90 return UIControls::GetNativeUIControls()->SendMouseMoveNotifyWhenDone( |
| 91 x, y, task); |
| 92 } |
| 93 |
| 94 bool SendMouseEvents(MouseButton type, int state) { |
| 95 return UIControls::GetNativeUIControls()->SendMouseEvents(type, state); |
| 96 } |
| 97 |
| 98 bool SendMouseEventsNotifyWhenDone( |
| 99 MouseButton type, int state, |
| 100 const base::Closure& task) { |
| 101 return UIControls::GetNativeUIControls()->SendMouseEventsNotifyWhenDone( |
| 102 type, state, task); |
| 103 } |
| 104 |
| 105 bool SendMouseClick(MouseButton type) { |
| 106 return UIControls::GetNativeUIControls()->SendMouseClick(type); |
| 107 } |
| 108 |
| 109 #if defined(TOOLKIT_VIEWS) |
| 110 UI_EXPORT void RunClosureAfterAllPendingUIEvents(const base::Closure& closure) { |
| 111 return UIControls::GetNativeUIControls()->RunClosureAfterAllPendingUIEvents( |
| 112 closure); |
| 113 } |
| 114 #endif |
| 115 |
| 116 } // namespace ui_controls |
| OLD | NEW |