2015-05-04 22:25:00 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "AccessibleCaret.h"
|
|
|
|
|
|
|
|
#include "AccessibleCaretLogger.h"
|
2016-02-15 13:29:32 +03:00
|
|
|
#include "mozilla/FloatingPoint.h"
|
2019-04-16 10:25:10 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2019-07-26 04:10:23 +03:00
|
|
|
#include "mozilla/StaticPrefs_layout.h"
|
2015-09-09 11:47:20 +03:00
|
|
|
#include "mozilla/ToString.h"
|
2015-05-04 22:25:00 +03:00
|
|
|
#include "nsCanvasFrame.h"
|
|
|
|
#include "nsCaret.h"
|
2017-11-07 03:20:34 +03:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2015-05-04 22:25:00 +03:00
|
|
|
#include "nsDOMTokenList.h"
|
|
|
|
#include "nsIFrame.h"
|
2017-11-07 03:20:34 +03:00
|
|
|
#include "nsPlaceholderFrame.h"
|
2015-05-04 22:25:00 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
using namespace dom;
|
|
|
|
|
|
|
|
#undef AC_LOG
|
|
|
|
#define AC_LOG(message, ...) \
|
|
|
|
AC_LOG_BASE("AccessibleCaret (%p): " message, this, ##__VA_ARGS__);
|
|
|
|
|
|
|
|
#undef AC_LOGV
|
|
|
|
#define AC_LOGV(message, ...) \
|
|
|
|
AC_LOGV_BASE("AccessibleCaret (%p): " message, this, ##__VA_ARGS__);
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(AccessibleCaret::DummyTouchListener, nsIDOMEventListener)
|
|
|
|
|
2020-07-01 11:42:31 +03:00
|
|
|
const nsLiteralString AccessibleCaret::sTextOverlayElementId =
|
|
|
|
u"text-overlay"_ns;
|
|
|
|
const nsLiteralString AccessibleCaret::sCaretImageElementId = u"image"_ns;
|
2016-08-18 10:09:19 +03:00
|
|
|
|
2015-09-18 20:05:19 +03:00
|
|
|
#define AC_PROCESS_ENUM_TO_STREAM(e) \
|
|
|
|
case (e): \
|
|
|
|
aStream << #e; \
|
|
|
|
break;
|
2015-09-09 11:47:20 +03:00
|
|
|
std::ostream& operator<<(std::ostream& aStream,
|
|
|
|
const AccessibleCaret::Appearance& aAppearance) {
|
|
|
|
using Appearance = AccessibleCaret::Appearance;
|
|
|
|
switch (aAppearance) {
|
2015-09-18 20:05:19 +03:00
|
|
|
AC_PROCESS_ENUM_TO_STREAM(Appearance::None);
|
|
|
|
AC_PROCESS_ENUM_TO_STREAM(Appearance::Normal);
|
|
|
|
AC_PROCESS_ENUM_TO_STREAM(Appearance::NormalNotShown);
|
|
|
|
AC_PROCESS_ENUM_TO_STREAM(Appearance::Left);
|
|
|
|
AC_PROCESS_ENUM_TO_STREAM(Appearance::Right);
|
2015-09-09 11:47:20 +03:00
|
|
|
}
|
2015-09-18 20:05:19 +03:00
|
|
|
return aStream;
|
|
|
|
}
|
2015-09-09 11:47:20 +03:00
|
|
|
|
2015-09-18 20:05:19 +03:00
|
|
|
std::ostream& operator<<(
|
|
|
|
std::ostream& aStream,
|
|
|
|
const AccessibleCaret::PositionChangedResult& aResult) {
|
|
|
|
using PositionChangedResult = AccessibleCaret::PositionChangedResult;
|
|
|
|
switch (aResult) {
|
|
|
|
AC_PROCESS_ENUM_TO_STREAM(PositionChangedResult::NotChanged);
|
2020-02-08 01:31:40 +03:00
|
|
|
AC_PROCESS_ENUM_TO_STREAM(PositionChangedResult::Position);
|
|
|
|
AC_PROCESS_ENUM_TO_STREAM(PositionChangedResult::Zoom);
|
2015-09-18 20:05:19 +03:00
|
|
|
AC_PROCESS_ENUM_TO_STREAM(PositionChangedResult::Invisible);
|
|
|
|
}
|
2015-09-09 11:47:20 +03:00
|
|
|
return aStream;
|
|
|
|
}
|
2015-09-18 20:05:19 +03:00
|
|
|
#undef AC_PROCESS_ENUM_TO_STREAM
|
2015-09-09 11:47:20 +03:00
|
|
|
|
2015-05-04 22:25:00 +03:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Implementation of AccessibleCaret methods
|
|
|
|
|
2019-04-16 10:25:10 +03:00
|
|
|
AccessibleCaret::AccessibleCaret(PresShell* aPresShell)
|
2015-05-04 22:25:00 +03:00
|
|
|
: mPresShell(aPresShell) {
|
|
|
|
// Check all resources required.
|
2015-09-18 20:05:18 +03:00
|
|
|
if (mPresShell) {
|
|
|
|
MOZ_ASSERT(RootFrame());
|
|
|
|
MOZ_ASSERT(mPresShell->GetDocument());
|
|
|
|
InjectCaretElement(mPresShell->GetDocument());
|
|
|
|
}
|
2015-05-04 22:25:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
AccessibleCaret::~AccessibleCaret() {
|
2015-09-18 20:05:18 +03:00
|
|
|
if (mPresShell) {
|
|
|
|
RemoveCaretElement(mPresShell->GetDocument());
|
|
|
|
}
|
2015-05-04 22:25:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AccessibleCaret::SetAppearance(Appearance aAppearance) {
|
|
|
|
if (mAppearance == aAppearance) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorResult rv;
|
2018-08-13 12:56:48 +03:00
|
|
|
CaretElement().ClassList()->Remove(AppearanceString(mAppearance), rv);
|
2015-05-04 22:25:00 +03:00
|
|
|
MOZ_ASSERT(!rv.Failed(), "Remove old appearance failed!");
|
|
|
|
|
2018-08-13 12:56:48 +03:00
|
|
|
CaretElement().ClassList()->Add(AppearanceString(aAppearance), rv);
|
2015-05-04 22:25:00 +03:00
|
|
|
MOZ_ASSERT(!rv.Failed(), "Add new appearance failed!");
|
|
|
|
|
2015-09-09 11:47:20 +03:00
|
|
|
AC_LOG("%s: %s -> %s", __FUNCTION__, ToString(mAppearance).c_str(),
|
|
|
|
ToString(aAppearance).c_str());
|
|
|
|
|
2015-05-04 22:25:00 +03:00
|
|
|
mAppearance = aAppearance;
|
|
|
|
|
|
|
|
// Need to reset rect since the cached rect will be compared in SetPosition.
|
|
|
|
if (mAppearance == Appearance::None) {
|
2019-11-02 01:19:18 +03:00
|
|
|
ClearCachedData();
|
2015-05-04 22:25:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
nsAutoString AccessibleCaret::AppearanceString(Appearance aAppearance) {
|
2015-05-04 22:25:00 +03:00
|
|
|
nsAutoString string;
|
|
|
|
switch (aAppearance) {
|
|
|
|
case Appearance::None:
|
|
|
|
case Appearance::NormalNotShown:
|
2020-07-01 11:29:29 +03:00
|
|
|
string = u"none"_ns;
|
2015-05-04 22:25:00 +03:00
|
|
|
break;
|
|
|
|
case Appearance::Normal:
|
2020-07-01 11:29:29 +03:00
|
|
|
string = u"normal"_ns;
|
2015-05-04 22:25:00 +03:00
|
|
|
break;
|
|
|
|
case Appearance::Right:
|
2020-07-01 11:29:29 +03:00
|
|
|
string = u"right"_ns;
|
2015-05-04 22:25:00 +03:00
|
|
|
break;
|
|
|
|
case Appearance::Left:
|
2020-07-01 11:29:29 +03:00
|
|
|
string = u"left"_ns;
|
2015-05-04 22:25:00 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AccessibleCaret::Intersects(const AccessibleCaret& aCaret) const {
|
|
|
|
MOZ_ASSERT(mPresShell == aCaret.mPresShell);
|
|
|
|
|
|
|
|
if (!IsVisuallyVisible() || !aCaret.IsVisuallyVisible()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-13 12:56:48 +03:00
|
|
|
nsRect rect =
|
|
|
|
nsLayoutUtils::GetRectRelativeToFrame(&CaretElement(), RootFrame());
|
|
|
|
nsRect rhsRect = nsLayoutUtils::GetRectRelativeToFrame(&aCaret.CaretElement(),
|
|
|
|
RootFrame());
|
2015-05-04 22:25:00 +03:00
|
|
|
return rect.Intersects(rhsRect);
|
|
|
|
}
|
|
|
|
|
2016-08-14 16:39:30 +03:00
|
|
|
bool AccessibleCaret::Contains(const nsPoint& aPoint,
|
|
|
|
TouchArea aTouchArea) const {
|
2015-05-04 22:25:00 +03:00
|
|
|
if (!IsVisuallyVisible()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-14 15:22:04 +03:00
|
|
|
nsRect textOverlayRect =
|
|
|
|
nsLayoutUtils::GetRectRelativeToFrame(TextOverlayElement(), RootFrame());
|
|
|
|
nsRect caretImageRect =
|
2015-05-04 22:25:00 +03:00
|
|
|
nsLayoutUtils::GetRectRelativeToFrame(CaretImageElement(), RootFrame());
|
|
|
|
|
2016-08-14 16:39:30 +03:00
|
|
|
if (aTouchArea == TouchArea::CaretImage) {
|
|
|
|
return caretImageRect.Contains(aPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(aTouchArea == TouchArea::Full, "Unexpected TouchArea type!");
|
2016-08-14 15:22:04 +03:00
|
|
|
return textOverlayRect.Contains(aPoint) || caretImageRect.Contains(aPoint);
|
2015-05-04 22:25:00 +03:00
|
|
|
}
|
|
|
|
|
2016-07-11 15:16:39 +03:00
|
|
|
void AccessibleCaret::EnsureApzAware() {
|
|
|
|
// If the caret element was cloned, the listener might have been lost. So
|
|
|
|
// if that's the case we register a dummy listener if there isn't one on
|
|
|
|
// the element already.
|
2018-08-13 12:56:48 +03:00
|
|
|
if (!CaretElement().IsApzAware()) {
|
|
|
|
// FIXME(emilio): Is this needed anymore?
|
2020-07-01 11:29:29 +03:00
|
|
|
CaretElement().AddEventListener(u"touchstart"_ns, mDummyTouchListener,
|
|
|
|
false);
|
2016-07-11 15:16:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-02 06:05:28 +03:00
|
|
|
bool AccessibleCaret::IsInPositionFixedSubtree() const {
|
2020-07-05 14:43:20 +03:00
|
|
|
return nsLayoutUtils::IsInPositionFixedSubtree(
|
|
|
|
mImaginaryCaretReferenceFrame.GetFrame());
|
2019-11-02 06:05:28 +03:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
void AccessibleCaret::InjectCaretElement(Document* aDocument) {
|
2015-05-04 22:25:00 +03:00
|
|
|
ErrorResult rv;
|
2018-08-13 12:56:48 +03:00
|
|
|
RefPtr<Element> element = CreateCaretElement(aDocument);
|
2015-05-04 22:25:00 +03:00
|
|
|
mCaretElementHolder = aDocument->InsertAnonymousContent(*element, rv);
|
|
|
|
|
|
|
|
MOZ_ASSERT(!rv.Failed(), "Insert anonymous content should not fail!");
|
2018-08-13 12:56:48 +03:00
|
|
|
MOZ_ASSERT(mCaretElementHolder, "We must have anonymous content!");
|
2015-05-04 22:25:00 +03:00
|
|
|
|
|
|
|
// InsertAnonymousContent will clone the element to make an AnonymousContent.
|
|
|
|
// Since event listeners are not being cloned when cloning a node, we need to
|
|
|
|
// add the listener here.
|
2016-07-11 15:16:39 +03:00
|
|
|
EnsureApzAware();
|
2015-05-04 22:25:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Element> AccessibleCaret::CreateCaretElement(
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aDocument) const {
|
2015-05-04 22:25:00 +03:00
|
|
|
// Content structure of AccessibleCaret
|
|
|
|
// <div class="moz-accessiblecaret"> <- CaretElement()
|
2019-11-02 01:16:08 +03:00
|
|
|
// <div id="text-overlay"> <- TextOverlayElement()
|
2016-08-18 10:09:19 +03:00
|
|
|
// <div id="image"> <- CaretImageElement()
|
2015-05-04 22:25:00 +03:00
|
|
|
|
|
|
|
ErrorResult rv;
|
2018-08-13 12:56:48 +03:00
|
|
|
RefPtr<Element> parent = aDocument->CreateHTMLElement(nsGkAtoms::div);
|
2020-07-01 11:29:29 +03:00
|
|
|
parent->ClassList()->Add(u"moz-accessiblecaret"_ns, rv);
|
|
|
|
parent->ClassList()->Add(u"none"_ns, rv);
|
2015-05-04 22:25:00 +03:00
|
|
|
|
2016-08-18 10:09:19 +03:00
|
|
|
auto CreateAndAppendChildElement =
|
|
|
|
[aDocument, &parent](const nsLiteralString& aElementId) {
|
2018-08-13 12:56:48 +03:00
|
|
|
RefPtr<Element> child = aDocument->CreateHTMLElement(nsGkAtoms::div);
|
2016-08-18 10:09:19 +03:00
|
|
|
child->SetAttr(kNameSpaceID_None, nsGkAtoms::id, aElementId, true);
|
|
|
|
parent->AppendChildTo(child, false);
|
|
|
|
};
|
2015-05-04 22:25:00 +03:00
|
|
|
|
2016-08-14 15:22:04 +03:00
|
|
|
CreateAndAppendChildElement(sTextOverlayElementId);
|
2016-08-18 10:09:19 +03:00
|
|
|
CreateAndAppendChildElement(sCaretImageElementId);
|
2015-05-04 22:25:00 +03:00
|
|
|
|
|
|
|
return parent.forget();
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
void AccessibleCaret::RemoveCaretElement(Document* aDocument) {
|
2020-07-01 11:29:29 +03:00
|
|
|
CaretElement().RemoveEventListener(u"touchstart"_ns, mDummyTouchListener,
|
|
|
|
false);
|
2015-05-04 22:25:00 +03:00
|
|
|
|
2018-08-13 12:56:48 +03:00
|
|
|
aDocument->RemoveAnonymousContent(*mCaretElementHolder, IgnoreErrors());
|
2015-05-04 22:25:00 +03:00
|
|
|
}
|
|
|
|
|
2019-11-02 01:19:18 +03:00
|
|
|
void AccessibleCaret::ClearCachedData() {
|
|
|
|
mImaginaryCaretRect = nsRect();
|
|
|
|
mImaginaryCaretRectInContainerFrame = nsRect();
|
2019-11-02 06:05:28 +03:00
|
|
|
mImaginaryCaretReferenceFrame = nullptr;
|
2019-11-02 01:19:18 +03:00
|
|
|
mZoomLevel = 0.0f;
|
|
|
|
}
|
|
|
|
|
2015-05-04 22:25:00 +03:00
|
|
|
AccessibleCaret::PositionChangedResult AccessibleCaret::SetPosition(
|
|
|
|
nsIFrame* aFrame, int32_t aOffset) {
|
|
|
|
if (!CustomContentContainerFrame()) {
|
|
|
|
return PositionChangedResult::NotChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect imaginaryCaretRectInFrame =
|
|
|
|
nsCaret::GetGeometryForFrame(aFrame, aOffset, nullptr);
|
|
|
|
|
|
|
|
imaginaryCaretRectInFrame =
|
|
|
|
nsLayoutUtils::ClampRectToScrollFrames(aFrame, imaginaryCaretRectInFrame);
|
|
|
|
|
|
|
|
if (imaginaryCaretRectInFrame.IsEmpty()) {
|
|
|
|
// Don't bother to set the caret position since it's invisible.
|
2019-11-02 01:19:18 +03:00
|
|
|
ClearCachedData();
|
2015-05-04 22:25:00 +03:00
|
|
|
return PositionChangedResult::Invisible;
|
|
|
|
}
|
|
|
|
|
2019-11-02 01:19:18 +03:00
|
|
|
// SetCaretElementStyle() requires the input rect relative to the custom
|
|
|
|
// content container frame.
|
|
|
|
nsRect imaginaryCaretRectInContainerFrame = imaginaryCaretRectInFrame;
|
|
|
|
nsLayoutUtils::TransformRect(aFrame, CustomContentContainerFrame(),
|
|
|
|
imaginaryCaretRectInContainerFrame);
|
|
|
|
const float zoomLevel = GetZoomLevel();
|
2020-02-08 01:31:40 +03:00
|
|
|
const bool isSamePosition = imaginaryCaretRectInContainerFrame.IsEqualEdges(
|
|
|
|
mImaginaryCaretRectInContainerFrame);
|
|
|
|
const bool isSameZoomLevel = FuzzyEqualsMultiplicative(zoomLevel, mZoomLevel);
|
2015-05-04 22:25:00 +03:00
|
|
|
|
2020-02-08 01:31:40 +03:00
|
|
|
if (isSamePosition && isSameZoomLevel) {
|
2015-05-04 22:25:00 +03:00
|
|
|
return PositionChangedResult::NotChanged;
|
|
|
|
}
|
|
|
|
|
2019-11-02 01:19:18 +03:00
|
|
|
nsRect imaginaryCaretRect = imaginaryCaretRectInFrame;
|
|
|
|
nsLayoutUtils::TransformRect(aFrame, RootFrame(), imaginaryCaretRect);
|
|
|
|
|
|
|
|
// Cache mImaginaryCaretRect, which is relative to the root frame.
|
2015-05-04 22:25:00 +03:00
|
|
|
mImaginaryCaretRect = imaginaryCaretRect;
|
2019-11-02 01:19:18 +03:00
|
|
|
mImaginaryCaretRectInContainerFrame = imaginaryCaretRectInContainerFrame;
|
2019-11-02 06:05:28 +03:00
|
|
|
mImaginaryCaretReferenceFrame = aFrame;
|
2016-02-15 13:29:32 +03:00
|
|
|
mZoomLevel = zoomLevel;
|
2015-05-04 22:25:00 +03:00
|
|
|
|
2016-02-15 13:29:32 +03:00
|
|
|
SetCaretElementStyle(imaginaryCaretRectInContainerFrame, mZoomLevel);
|
2015-05-04 22:25:00 +03:00
|
|
|
|
2020-02-08 01:31:40 +03:00
|
|
|
return isSamePosition ? PositionChangedResult::Zoom
|
|
|
|
: PositionChangedResult::Position;
|
2015-05-04 22:25:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* AccessibleCaret::CustomContentContainerFrame() const {
|
|
|
|
nsCanvasFrame* canvasFrame = mPresShell->GetCanvasFrame();
|
|
|
|
Element* container = canvasFrame->GetCustomContentContainer();
|
|
|
|
nsIFrame* containerFrame = container->GetPrimaryFrame();
|
|
|
|
return containerFrame;
|
|
|
|
}
|
|
|
|
|
2016-02-15 13:29:32 +03:00
|
|
|
void AccessibleCaret::SetCaretElementStyle(const nsRect& aRect,
|
|
|
|
float aZoomLevel) {
|
2015-05-04 22:25:00 +03:00
|
|
|
nsPoint position = CaretElementPosition(aRect);
|
|
|
|
nsAutoString styleStr;
|
2017-03-15 06:16:32 +03:00
|
|
|
// We can't use AppendPrintf here, because it does locale-specific
|
|
|
|
// formatting of floating-point values.
|
2019-11-02 01:16:08 +03:00
|
|
|
styleStr.AppendLiteral("left: ");
|
|
|
|
styleStr.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(position.x));
|
|
|
|
styleStr.AppendLiteral("px; top: ");
|
|
|
|
styleStr.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(position.y));
|
|
|
|
styleStr.AppendLiteral("px; width: ");
|
2018-09-22 00:48:27 +03:00
|
|
|
styleStr.AppendFloat(StaticPrefs::layout_accessiblecaret_width() /
|
|
|
|
aZoomLevel);
|
2017-03-15 06:16:32 +03:00
|
|
|
styleStr.AppendLiteral("px; margin-left: ");
|
2018-09-22 00:48:27 +03:00
|
|
|
styleStr.AppendFloat(StaticPrefs::layout_accessiblecaret_margin_left() /
|
|
|
|
aZoomLevel);
|
2017-03-15 06:16:32 +03:00
|
|
|
styleStr.AppendLiteral("px");
|
2015-05-15 19:05:00 +03:00
|
|
|
|
2018-08-13 12:56:48 +03:00
|
|
|
CaretElement().SetAttr(kNameSpaceID_None, nsGkAtoms::style, styleStr, true);
|
2016-08-14 15:22:04 +03:00
|
|
|
AC_LOG("%s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(styleStr).get());
|
2015-05-04 22:25:00 +03:00
|
|
|
|
2016-08-14 15:22:04 +03:00
|
|
|
// Set style string for children.
|
|
|
|
SetTextOverlayElementStyle(aRect, aZoomLevel);
|
|
|
|
SetCaretImageElementStyle(aRect, aZoomLevel);
|
2015-05-04 22:25:00 +03:00
|
|
|
}
|
|
|
|
|
2016-08-14 15:22:04 +03:00
|
|
|
void AccessibleCaret::SetTextOverlayElementStyle(const nsRect& aRect,
|
|
|
|
float aZoomLevel) {
|
|
|
|
nsAutoString styleStr;
|
2019-11-02 01:16:08 +03:00
|
|
|
styleStr.AppendLiteral("height: ");
|
|
|
|
styleStr.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(aRect.height));
|
|
|
|
styleStr.AppendLiteral("px;");
|
2016-08-14 15:22:04 +03:00
|
|
|
TextOverlayElement()->SetAttr(kNameSpaceID_None, nsGkAtoms::style, styleStr,
|
|
|
|
true);
|
|
|
|
AC_LOG("%s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(styleStr).get());
|
|
|
|
}
|
2015-05-15 19:05:00 +03:00
|
|
|
|
2016-08-14 15:22:04 +03:00
|
|
|
void AccessibleCaret::SetCaretImageElementStyle(const nsRect& aRect,
|
|
|
|
float aZoomLevel) {
|
|
|
|
nsAutoString styleStr;
|
2019-11-02 01:16:08 +03:00
|
|
|
styleStr.AppendLiteral("height: ");
|
|
|
|
styleStr.AppendFloat(StaticPrefs::layout_accessiblecaret_height() /
|
|
|
|
aZoomLevel);
|
|
|
|
styleStr.AppendLiteral("px;");
|
2016-08-14 15:22:04 +03:00
|
|
|
CaretImageElement()->SetAttr(kNameSpaceID_None, nsGkAtoms::style, styleStr,
|
|
|
|
true);
|
|
|
|
AC_LOG("%s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(styleStr).get());
|
|
|
|
}
|
2015-05-04 22:25:00 +03:00
|
|
|
|
2015-05-15 19:05:00 +03:00
|
|
|
float AccessibleCaret::GetZoomLevel() {
|
|
|
|
// Full zoom on desktop.
|
|
|
|
float fullZoom = mPresShell->GetPresContext()->GetFullZoom();
|
|
|
|
|
2017-04-20 08:16:42 +03:00
|
|
|
// Pinch-zoom on fennec.
|
2015-05-15 19:05:00 +03:00
|
|
|
float resolution = mPresShell->GetCumulativeResolution();
|
|
|
|
|
|
|
|
return fullZoom * resolution;
|
|
|
|
}
|
|
|
|
|
2015-05-04 22:25:00 +03:00
|
|
|
} // namespace mozilla
|