Chromium Code Reviews| Index: ui/ui_controls/ui_controls.cc |
| diff --git a/ui/ui_controls/ui_controls.cc b/ui/ui_controls/ui_controls.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bf065b40234a410a5902665a04bcaa7237d4a1cb |
| --- /dev/null |
| +++ b/ui/ui_controls/ui_controls.cc |
| @@ -0,0 +1,115 @@ |
| +// Copyright 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/ui_controls/ui_controls.h" |
| + |
| +#include "base/logging.h" |
| + |
| +namespace ui_controls { |
| + |
| +namespace { |
| + |
| +UIControls* g_ui_controls_[UI_CONTROLS_TYPE_LAST + 1]; |
|
oshima
2012/11/15 23:37:41
= { 0 }
(You don't really need for arrays, but ju
scottmg
2012/11/16 17:58:54
Done.
|
| +UIControlsTypeDelegate* g_ui_controls_type_delegate_ = NULL; |
|
oshima
2012/11/15 23:37:41
optional: my understanding is that g_ is for globa
scottmg
2012/11/16 17:58:54
Done.
|
| + |
| +} // namespace |
| + |
| +UIControls::UIControls() { |
| +} |
| + |
| +UIControls::~UIControls() { |
| +} |
| + |
| +// static |
| +UIControls* UIControls::GetUIControlsFor(gfx::NativeView view) { |
| + UIControlsType type = UI_CONTROLS_TYPE_NATIVE; |
| + if (g_ui_controls_type_delegate_) |
| + type = g_ui_controls_type_delegate_->GetUIControlsTypeForNativeView(view); |
| + if (type == UI_CONTROLS_TYPE_NATIVE) |
| + return GetNativeUIControls(); |
| + DCHECK(g_ui_controls_[type]); |
| + return g_ui_controls_[type]; |
| +} |
| + |
| +// static |
| +void UIControls::SetUIControlsInstance( |
| + UIControlsType type, UIControls* instance) { |
| + DCHECK_LE(type, UI_CONTROLS_TYPE_LAST); |
| + g_ui_controls_[type] = instance; |
| +} |
| + |
| +// static |
| +UIControls* UIControls::GetUIControlsByType(UIControlsType type) { |
| + return g_ui_controls_[type]; |
| +} |
| + |
| +// static |
| +void UIControls::SetUIControlsTypeDelegate(UIControlsTypeDelegate* delegate) { |
| + g_ui_controls_type_delegate_ = delegate; |
| +} |
| + |
| +// static |
| +UIControls* UIControls::GetNativeUIControls() { |
| + if (!g_ui_controls_[UI_CONTROLS_TYPE_NATIVE]) |
| + g_ui_controls_[UI_CONTROLS_TYPE_NATIVE] = CreateNativeUIControls(); |
| + return g_ui_controls_[UI_CONTROLS_TYPE_NATIVE]; |
| +} |
| + |
| + |
| +// ALL OF THESE ARE DEPRECATED, SEE HEADER. http://crbug.com/128578 |
| +bool SendKeyPress(gfx::NativeWindow window, |
| + ui::KeyboardCode key, |
| + bool control, |
| + bool shift, |
| + bool alt, |
| + bool command) { |
| + return UIControls::GetNativeUIControls()->SendKeyPress( |
| + window, key, control, shift, alt, command); |
| +} |
| + |
| +bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, |
| + ui::KeyboardCode key, |
| + bool control, |
| + bool shift, |
| + bool alt, |
| + bool command, |
| + const base::Closure& task) { |
| + return UIControls::GetNativeUIControls()->SendKeyPressNotifyWhenDone( |
| + window, key, control, shift, alt, command, task); |
| +} |
| + |
| +bool SendMouseMove(long x, long y) { |
| + return UIControls::GetNativeUIControls()->SendMouseMove(x, y); |
| +} |
| + |
| +bool SendMouseMoveNotifyWhenDone(long x, |
| + long y, |
| + const base::Closure& task) { |
|
oshima
2012/11/15 23:37:41
indent
scottmg
2012/11/16 17:58:54
Done.
|
| + return UIControls::GetNativeUIControls()->SendMouseMoveNotifyWhenDone( |
| + x, y, task); |
| +} |
| + |
| +bool SendMouseEvents(MouseButton type, int state) { |
| + return UIControls::GetNativeUIControls()->SendMouseEvents(type, state); |
| +} |
| + |
| +bool SendMouseEventsNotifyWhenDone( |
| + MouseButton type, int state, |
| + const base::Closure& task) { |
| + return UIControls::GetNativeUIControls()->SendMouseEventsNotifyWhenDone( |
| + type, state, task); |
| +} |
| + |
| +bool SendMouseClick(MouseButton type) { |
| + return UIControls::GetNativeUIControls()->SendMouseClick(type); |
| +} |
| + |
| +#if defined(TOOLKIT_VIEWS) |
| +UI_EXPORT void RunClosureAfterAllPendingUIEvents(const base::Closure& closure) { |
| + return UIControls::GetNativeUIControls()->RunClosureAfterAllPendingUIEvents( |
| + closure); |
| +} |
| +#endif |
| + |
| +} // namespace ui_controls |