#include "UniversalSwitch.hpp"
#include "UniversalSwitchLog.hpp"
#include "Window.hpp"
+#include "TextToSpeech.hpp"
#include <Elementary.h>
atspi->getAtPoint(pt, Atspi::CoordType::Screen, elem->getVisibleRoot(),
[ = ](DBus::ValueOrError<std::shared_ptr<AtspiAccessible>> elem) {
auto uiElem = std::make_shared<UIElement>(elem ? std::move(std::get<0>(elem)) : nullptr, pt, application);
+ auto tts = Singleton<UniversalSwitch>::instance().getTextToSpeech();
+ if (tts)
+ tts->speak(uiElem->getObject());
callback(std::move(uiElem));
});
} else {
namespace
{
- void playFeedback(const AtspiAccessiblePtr &atspiElem)
- {
- auto tts = Singleton<UniversalSwitch>::instance().getTextToSpeech();
- if (tts->isEnabled()) {
- Singleton<UniversalSwitch>::instance().getTextToSpeech()->speak(atspiElem);
- }
- Singleton<UniversalSwitch>::instance().getSoundFeedback()->play(SoundFeedback::Sound::NAVIGATION_ITERATED);
- }
-
- static const std::string BACK_BUTTON_CODE = "XF86Back";
+ const char *BACK_BUTTON_CODE = "XF86Back";
+ const char *IDS_ESCAPE = "IDS_ESCAPE";
+ const char *IDS_ROW = "IDS_ROW";
}
/**
void moveToNextPosition(bool invertDirection = false, bool movedByAutoScan = false);
int getFirstElementIndex(const std::shared_ptr<NavigationElement> &parent, bool invertDirection = false);
int getIncrementForCalculatingNextElement(const std::shared_ptr<NavigationElement> &parent, bool invertDirection = false);
+ void playFeedback();
ecore::Timer timer;
evas::Shape frame;
void RowScannerImpl::selectNewElement(NavigationState navState)
{
currentNavState = std::move(navState);
- Rectangle pos;
- if (currentNavState.childIndex) {
- auto c = currentNavState.parent->getChildren()[static_cast<size_t>(*currentNavState.childIndex)];
- pos = c->getBounds();
- playFeedback(c->getElement());
- } else {
- pos = currentNavState.parent->getBounds();
- playFeedback(nullptr);
- }
-
- drawFrame(pos, currentNavState.childIndex ?
- NavigationInterface::BoxPositionMode::NORMAL : NavigationInterface::BoxPositionMode::DASHED, properties.getColor());
+ auto &element = currentNavState.childIndex ?
+ currentNavState.parent->getChildren()[*currentNavState.childIndex] :
+ currentNavState.parent;
+
+ playFeedback();
+ drawFrame(element->getBounds(),
+ currentNavState.childIndex ?
+ NavigationInterface::BoxPositionMode::NORMAL :
+ NavigationInterface::BoxPositionMode::DASHED,
+ properties.getColor());
}
void RowScannerImpl::clearCursor()
selectNewElement({ std::move(p), index });
}
} else {
- auto c = currentNavState.parent->getChildren()[static_cast<size_t>(*currentNavState.childIndex)];
+ auto c = currentNavState.parent->getChildren()[*currentNavState.childIndex];
ASSERT(c);
while (c->getChildren().size() == 1) {
c = c->getChildren()[0];
selectNewElement({currentNavState.parent, getFirstElementIndex(currentNavState.parent, invertDirection)});
}
+
+void RowScannerImpl::playFeedback()
+{
+ Singleton<UniversalSwitch>::instance().getSoundFeedback()->play(SoundFeedback::Sound::NAVIGATION_ITERATED);
+ auto tts = Singleton<UniversalSwitch>::instance().getTextToSpeech();
+ if (!tts->isEnabled())
+ return;
+
+ if (!currentNavState.childIndex) {
+ tts->speak(std::string(_(IDS_ESCAPE)));
+ return;
+ }
+
+ auto &navigationElementHandler = currentNavState.parent->getChildren()[*currentNavState.childIndex];
+
+ if (currentNavState.parent->getScanningDirection() == NavigationElement::Direction::VERTICAL) {
+ if (navigationElementHandler->getChildren().size() == 1) {
+ tts->speak(navigationElementHandler->getChildren().front()->getElement());
+ return;
+ }
+
+ tts->speak(std::string(_(IDS_ROW)) + std::to_string(*currentNavState.childIndex + 1));
+ return;
+ }
+
+ tts->speak(navigationElementHandler->getElement());
+}