Chromium Code Reviews| 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); | |
|
oshima
2012/11/16 20:41:39
I was thinking about
delete g_ui_controls[type];
scottmg
2012/11/16 22:34:06
Done.
| |
| 39 g_ui_controls[type] = instance; | |
| 40 } | |
| 41 | |
| 42 // static | |
| 43 UIControls* UIControls::GetUIControlsByType(UIControlsType type) { | |
| 44 return g_ui_controls[type]; | |
| 45 } | |
| 46 | |
| 47 // static | |
| 48 void UIControls::SetUIControlsTypeDelegate(UIControlsTypeDelegate* delegate) { | |
| 49 g_ui_controls_type_delegate = delegate; | |
| 50 } | |
| 51 | |
| 52 // static | |
| 53 UIControls* UIControls::GetNativeUIControls() { | |
| 54 if (!g_ui_controls[UI_CONTROLS_TYPE_NATIVE]) | |
| 55 g_ui_controls[UI_CONTROLS_TYPE_NATIVE] = CreateNativeUIControls(); | |
| 56 return g_ui_controls[UI_CONTROLS_TYPE_NATIVE]; | |
| 57 } | |
| 58 | |
| 59 | |
| 60 // ALL OF THESE ARE DEPRECATED, SEE HEADER. http://crbug.com/128578 | |
| 61 bool SendKeyPress(gfx::NativeWindow window, | |
| 62 ui::KeyboardCode key, | |
| 63 bool control, | |
| 64 bool shift, | |
| 65 bool alt, | |
| 66 bool command) { | |
| 67 return UIControls::GetNativeUIControls()->SendKeyPress( | |
| 68 window, key, control, shift, alt, command); | |
| 69 } | |
| 70 | |
| 71 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, | |
| 72 ui::KeyboardCode key, | |
| 73 bool control, | |
| 74 bool shift, | |
| 75 bool alt, | |
| 76 bool command, | |
| 77 const base::Closure& task) { | |
| 78 return UIControls::GetNativeUIControls()->SendKeyPressNotifyWhenDone( | |
| 79 window, key, control, shift, alt, command, task); | |
| 80 } | |
| 81 | |
| 82 bool SendMouseMove(long x, long y) { | |
| 83 return UIControls::GetNativeUIControls()->SendMouseMove(x, y); | |
| 84 } | |
| 85 | |
| 86 bool SendMouseMoveNotifyWhenDone(long x, | |
| 87 long y, | |
| 88 const base::Closure& task) { | |
| 89 return UIControls::GetNativeUIControls()->SendMouseMoveNotifyWhenDone( | |
| 90 x, y, task); | |
| 91 } | |
| 92 | |
| 93 bool SendMouseEvents(MouseButton type, int state) { | |
| 94 return UIControls::GetNativeUIControls()->SendMouseEvents(type, state); | |
| 95 } | |
| 96 | |
| 97 bool SendMouseEventsNotifyWhenDone( | |
| 98 MouseButton type, int state, | |
| 99 const base::Closure& task) { | |
| 100 return UIControls::GetNativeUIControls()->SendMouseEventsNotifyWhenDone( | |
| 101 type, state, task); | |
| 102 } | |
| 103 | |
| 104 bool SendMouseClick(MouseButton type) { | |
| 105 return UIControls::GetNativeUIControls()->SendMouseClick(type); | |
| 106 } | |
| 107 | |
| 108 #if defined(TOOLKIT_VIEWS) | |
| 109 UI_EXPORT void RunClosureAfterAllPendingUIEvents(const base::Closure& closure) { | |
| 110 return UIControls::GetNativeUIControls()->RunClosureAfterAllPendingUIEvents( | |
| 111 closure); | |
| 112 } | |
| 113 #endif | |
| 114 | |
| 115 } // namespace ui_controls | |
| OLD | NEW |