diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-03-20 02:50:50 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-03-20 20:36:00 +0000 |
commit | dd5f85910e6103ffa3ffbc70e9c60a0f8dc4b427 (patch) | |
tree | 0620cd0dc83eeeb6e40fede2ae0416f56b12551c | |
parent | 231070fc9c94411e5a5feacc7b375886b8a904a2 (diff) |
uitest: start to log key input
We need to disable this part in release builds.
Change-Id: Ica57f8aca1ffb5f7938ab82ef8b888a8d6d6101a
Reviewed-on: https://gerrit.libreoffice.org/35450
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
-rw-r--r-- | include/vcl/uitest/logger.hxx | 2 | ||||
-rw-r--r-- | vcl/source/uitest/logger.cxx | 70 | ||||
-rw-r--r-- | vcl/source/window/winproc.cxx | 2 |
3 files changed, 74 insertions, 0 deletions
diff --git a/include/vcl/uitest/logger.hxx b/include/vcl/uitest/logger.hxx index 32625c7f60a7..5cf906eb510c 100644 --- a/include/vcl/uitest/logger.hxx +++ b/include/vcl/uitest/logger.hxx @@ -30,6 +30,8 @@ public: void log(const OUString& rString); + void logKeyInput(VclPtr<vcl::Window>& xUIElement, const KeyEvent& rEvent); + static UITestLogger& getInstance(); }; diff --git a/vcl/source/uitest/logger.cxx b/vcl/source/uitest/logger.cxx index d24efeb5d0a8..2549b7dd9a44 100644 --- a/vcl/source/uitest/logger.cxx +++ b/vcl/source/uitest/logger.cxx @@ -67,6 +67,76 @@ void UITestLogger::log(const OUString& rString) maStream.WriteLine(OUStringToOString(rString, RTL_TEXTENCODING_UTF8)); } +void UITestLogger::logKeyInput(VclPtr<vcl::Window>& xUIElement, const KeyEvent& rEvent) +{ + if (!mbValid) + return; + + const OUString& rID = xUIElement->get_id(); + if (rID.isEmpty()) + return; + + sal_Unicode nChar = rEvent.GetCharCode(); + sal_uInt16 nKeyCode = rEvent.GetKeyCode().GetCode(); + bool bShift = rEvent.GetKeyCode().IsShift(); + bool bMod1 = rEvent.GetKeyCode().IsMod1(); + bool bMod2 = rEvent.GetKeyCode().IsMod1(); + bool bMod3 = rEvent.GetKeyCode().IsMod1(); + + std::map<OUString, sal_uInt16> aKeyMap = { + {"ESC", KEY_ESCAPE}, + {"TAB", KEY_TAB}, + {"DOWN", KEY_DOWN}, + {"UP", KEY_UP}, + {"LEFT", KEY_LEFT}, + {"RIGHT", KEY_RIGHT}, + {"DELETE", KEY_DELETE}, + {"INSERT", KEY_INSERT}, + {"BACKSPACE", KEY_BACKSPACE}, + {"RETURN", KEY_RETURN}, + {"HOME", KEY_HOME}, + {"END", KEY_END}, + {"PAGEUP", KEY_PAGEUP}, + {"PAGEDOWN", KEY_PAGEDOWN} + }; + + OUString aFound; + for (auto& itr : aKeyMap) + { + if (itr.second == nKeyCode) + { + aFound = itr.first; + break; + } + } + + OUString aKeyCode; + if (!aFound.isEmpty() || bShift || bMod1 || bMod2 || bMod3) + { + aKeyCode = "{\"KEYCODE\": \""; + if (bShift) + aKeyCode += "SHIFT+"; + + if (bMod1) + aKeyCode += "CTRL+"; + + if (bMod2) + aKeyCode += "ALT+"; + + if (aFound.isEmpty()) + aKeyCode += OUStringLiteral1(nChar) + "\"}"; + else + aKeyCode += aFound + "\"}"; + } + else + { + aKeyCode = "{\"TEXT\": \"" + OUStringLiteral1(nChar) + "\"}"; + } + + OUString aContent = "Action on element: " + rID + " with action: TYPE and content: " + aKeyCode; + maStream.WriteLine(OUStringToOString(aContent, RTL_TEXTENCODING_UTF8)); +} + UITestLogger& UITestLogger::getInstance() { static UITestLogger aInstance; diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx index 55efefd60e63..567f1c969412 100644 --- a/vcl/source/window/winproc.cxx +++ b/vcl/source/window/winproc.cxx @@ -38,6 +38,7 @@ #include <vcl/virdev.hxx> #include <vcl/lazydelete.hxx> #include <touch/touch.h> +#include <vcl/uitest/logger.hxx> #include <svdata.hxx> #include <salwtype.hxx> @@ -986,6 +987,7 @@ static bool ImplHandleKey( vcl::Window* pWindow, MouseNotifyEvent nSVEvent, { if ( nSVEvent == MouseNotifyEvent::KEYINPUT ) { + UITestLogger::getInstance().logKeyInput(pChild, aKeyEvt); pChild->ImplGetWindowImpl()->mbKeyInput = false; pChild->KeyInput( aKeyEvt ); } |