2015-05-04 19:25:00 +00: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 10:29:32 +00:00
|
|
|
#include "mozilla/FloatingPoint.h"
|
2015-05-04 19:25:00 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2015-09-09 08:47:20 +00:00
|
|
|
#include "mozilla/ToString.h"
|
2015-05-04 19:25:00 +00:00
|
|
|
#include "nsCanvasFrame.h"
|
|
|
|
#include "nsCaret.h"
|
|
|
|
#include "nsDOMTokenList.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2015-05-15 16:05:00 +00:00
|
|
|
float AccessibleCaret::sWidth = 0.0f;
|
|
|
|
float AccessibleCaret::sHeight = 0.0f;
|
|
|
|
float AccessibleCaret::sMarginLeft = 0.0f;
|
|
|
|
float AccessibleCaret::sBarWidth = 0.0f;
|
|
|
|
|
2016-08-14 12:22:04 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(AccessibleCaret::sTextOverlayElementId, "text-overlay");
|
2016-08-18 07:09:19 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(AccessibleCaret::sCaretImageElementId, "image");
|
|
|
|
NS_NAMED_LITERAL_STRING(AccessibleCaret::sSelectionBarElementId, "bar");
|
|
|
|
|
2015-09-18 17:05:19 +00:00
|
|
|
#define AC_PROCESS_ENUM_TO_STREAM(e) case(e): aStream << #e; break;
|
2015-09-09 08:47:20 +00:00
|
|
|
std::ostream&
|
|
|
|
operator<<(std::ostream& aStream, const AccessibleCaret::Appearance& aAppearance)
|
|
|
|
{
|
|
|
|
using Appearance = AccessibleCaret::Appearance;
|
|
|
|
switch (aAppearance) {
|
2015-09-18 17:05:19 +00: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 08:47:20 +00:00
|
|
|
}
|
2015-09-18 17:05:19 +00:00
|
|
|
return aStream;
|
|
|
|
}
|
2015-09-09 08:47:20 +00:00
|
|
|
|
2015-09-18 17:05:19 +00:00
|
|
|
std::ostream&
|
|
|
|
operator<<(std::ostream& aStream,
|
|
|
|
const AccessibleCaret::PositionChangedResult& aResult)
|
|
|
|
{
|
|
|
|
using PositionChangedResult = AccessibleCaret::PositionChangedResult;
|
|
|
|
switch (aResult) {
|
|
|
|
AC_PROCESS_ENUM_TO_STREAM(PositionChangedResult::NotChanged);
|
|
|
|
AC_PROCESS_ENUM_TO_STREAM(PositionChangedResult::Changed);
|
|
|
|
AC_PROCESS_ENUM_TO_STREAM(PositionChangedResult::Invisible);
|
|
|
|
}
|
2015-09-09 08:47:20 +00:00
|
|
|
return aStream;
|
|
|
|
}
|
2015-09-18 17:05:19 +00:00
|
|
|
#undef AC_PROCESS_ENUM_TO_STREAM
|
2015-09-09 08:47:20 +00:00
|
|
|
|
2015-05-04 19:25:00 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Implementation of AccessibleCaret methods
|
|
|
|
|
|
|
|
AccessibleCaret::AccessibleCaret(nsIPresShell* aPresShell)
|
|
|
|
: mPresShell(aPresShell)
|
|
|
|
{
|
|
|
|
// Check all resources required.
|
2015-09-18 17:05:18 +00:00
|
|
|
if (mPresShell) {
|
|
|
|
MOZ_ASSERT(RootFrame());
|
|
|
|
MOZ_ASSERT(mPresShell->GetDocument());
|
|
|
|
MOZ_ASSERT(mPresShell->GetCanvasFrame());
|
|
|
|
MOZ_ASSERT(mPresShell->GetCanvasFrame()->GetCustomContentContainer());
|
2015-05-04 19:25:00 +00:00
|
|
|
|
2015-09-18 17:05:18 +00:00
|
|
|
InjectCaretElement(mPresShell->GetDocument());
|
|
|
|
}
|
2015-05-15 16:05:00 +00:00
|
|
|
|
|
|
|
static bool prefsAdded = false;
|
|
|
|
if (!prefsAdded) {
|
|
|
|
Preferences::AddFloatVarCache(&sWidth, "layout.accessiblecaret.width");
|
|
|
|
Preferences::AddFloatVarCache(&sHeight, "layout.accessiblecaret.height");
|
|
|
|
Preferences::AddFloatVarCache(&sMarginLeft, "layout.accessiblecaret.margin-left");
|
|
|
|
Preferences::AddFloatVarCache(&sBarWidth, "layout.accessiblecaret.bar.width");
|
|
|
|
prefsAdded = true;
|
|
|
|
}
|
2015-05-04 19:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AccessibleCaret::~AccessibleCaret()
|
|
|
|
{
|
2015-09-18 17:05:18 +00:00
|
|
|
if (mPresShell) {
|
|
|
|
RemoveCaretElement(mPresShell->GetDocument());
|
|
|
|
}
|
2015-05-04 19:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AccessibleCaret::SetAppearance(Appearance aAppearance)
|
|
|
|
{
|
|
|
|
if (mAppearance == aAppearance) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
CaretElement()->ClassList()->Remove(AppearanceString(mAppearance), rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed(), "Remove old appearance failed!");
|
|
|
|
|
|
|
|
CaretElement()->ClassList()->Add(AppearanceString(aAppearance), rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed(), "Add new appearance failed!");
|
|
|
|
|
2015-09-09 08:47:20 +00:00
|
|
|
AC_LOG("%s: %s -> %s", __FUNCTION__, ToString(mAppearance).c_str(),
|
|
|
|
ToString(aAppearance).c_str());
|
|
|
|
|
2015-05-04 19:25:00 +00:00
|
|
|
mAppearance = aAppearance;
|
|
|
|
|
|
|
|
// Need to reset rect since the cached rect will be compared in SetPosition.
|
|
|
|
if (mAppearance == Appearance::None) {
|
|
|
|
mImaginaryCaretRect = nsRect();
|
2016-02-15 10:29:32 +00:00
|
|
|
mZoomLevel = 0.0f;
|
2015-05-04 19:25:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AccessibleCaret::SetSelectionBarEnabled(bool aEnabled)
|
|
|
|
{
|
|
|
|
if (mSelectionBarEnabled == aEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-24 23:04:20 +00:00
|
|
|
AC_LOG("Set selection bar %s", aEnabled ? "Enabled" : "Disabled");
|
2015-05-04 19:25:00 +00:00
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
CaretElement()->ClassList()->Toggle(NS_LITERAL_STRING("no-bar"),
|
|
|
|
Optional<bool>(!aEnabled), rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
|
|
|
|
|
|
|
mSelectionBarEnabled = aEnabled;
|
|
|
|
}
|
|
|
|
|
2016-08-21 13:41:32 +00:00
|
|
|
/* static */ nsAutoString
|
2015-05-04 19:25:00 +00:00
|
|
|
AccessibleCaret::AppearanceString(Appearance aAppearance)
|
|
|
|
{
|
|
|
|
nsAutoString string;
|
|
|
|
switch (aAppearance) {
|
|
|
|
case Appearance::None:
|
|
|
|
case Appearance::NormalNotShown:
|
|
|
|
string = NS_LITERAL_STRING("none");
|
|
|
|
break;
|
|
|
|
case Appearance::Normal:
|
|
|
|
string = NS_LITERAL_STRING("normal");
|
|
|
|
break;
|
|
|
|
case Appearance::Right:
|
|
|
|
string = NS_LITERAL_STRING("right");
|
|
|
|
break;
|
|
|
|
case Appearance::Left:
|
|
|
|
string = NS_LITERAL_STRING("left");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AccessibleCaret::Intersects(const AccessibleCaret& aCaret) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mPresShell == aCaret.mPresShell);
|
|
|
|
|
|
|
|
if (!IsVisuallyVisible() || !aCaret.IsVisuallyVisible()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect rect = nsLayoutUtils::GetRectRelativeToFrame(CaretElement(), RootFrame());
|
|
|
|
nsRect rhsRect = nsLayoutUtils::GetRectRelativeToFrame(aCaret.CaretElement(), RootFrame());
|
|
|
|
return rect.Intersects(rhsRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-08-14 13:39:30 +00:00
|
|
|
AccessibleCaret::Contains(const nsPoint& aPoint, TouchArea aTouchArea) const
|
2015-05-04 19:25:00 +00:00
|
|
|
{
|
|
|
|
if (!IsVisuallyVisible()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-14 12:22:04 +00:00
|
|
|
nsRect textOverlayRect =
|
|
|
|
nsLayoutUtils::GetRectRelativeToFrame(TextOverlayElement(), RootFrame());
|
|
|
|
nsRect caretImageRect =
|
2015-05-04 19:25:00 +00:00
|
|
|
nsLayoutUtils::GetRectRelativeToFrame(CaretImageElement(), RootFrame());
|
|
|
|
|
2016-08-14 13:39:30 +00:00
|
|
|
if (aTouchArea == TouchArea::CaretImage) {
|
|
|
|
return caretImageRect.Contains(aPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(aTouchArea == TouchArea::Full, "Unexpected TouchArea type!");
|
2016-08-14 12:22:04 +00:00
|
|
|
return textOverlayRect.Contains(aPoint) || caretImageRect.Contains(aPoint);
|
2015-05-04 19:25:00 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 12:16:39 +00: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.
|
|
|
|
if (!CaretElement()->IsApzAware()) {
|
|
|
|
CaretElement()->AddEventListener(NS_LITERAL_STRING("touchstart"),
|
|
|
|
mDummyTouchListener, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-04 19:25:00 +00:00
|
|
|
void
|
|
|
|
AccessibleCaret::InjectCaretElement(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
nsCOMPtr<Element> element = CreateCaretElement(aDocument);
|
|
|
|
mCaretElementHolder = aDocument->InsertAnonymousContent(*element, rv);
|
|
|
|
|
|
|
|
MOZ_ASSERT(!rv.Failed(), "Insert anonymous content should not fail!");
|
|
|
|
MOZ_ASSERT(mCaretElementHolder.get(), "We must have anonymous content!");
|
|
|
|
|
|
|
|
// 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 12:16:39 +00:00
|
|
|
EnsureApzAware();
|
2015-05-04 19:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Element>
|
|
|
|
AccessibleCaret::CreateCaretElement(nsIDocument* aDocument) const
|
|
|
|
{
|
|
|
|
// Content structure of AccessibleCaret
|
|
|
|
// <div class="moz-accessiblecaret"> <- CaretElement()
|
2016-08-14 12:22:04 +00:00
|
|
|
// <div id="text-overlay" <- TextOverlayElement()
|
2016-08-18 07:09:19 +00:00
|
|
|
// <div id="image"> <- CaretImageElement()
|
|
|
|
// <div id="bar"> <- SelectionBarElement()
|
2015-05-04 19:25:00 +00:00
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
nsCOMPtr<Element> parent = aDocument->CreateHTMLElement(nsGkAtoms::div);
|
|
|
|
parent->ClassList()->Add(NS_LITERAL_STRING("moz-accessiblecaret"), rv);
|
|
|
|
parent->ClassList()->Add(NS_LITERAL_STRING("none"), rv);
|
|
|
|
parent->ClassList()->Add(NS_LITERAL_STRING("no-bar"), rv);
|
|
|
|
|
2016-08-18 07:09:19 +00:00
|
|
|
auto CreateAndAppendChildElement = [aDocument, &parent](
|
|
|
|
const nsLiteralString& aElementId)
|
|
|
|
{
|
|
|
|
nsCOMPtr<Element> child = aDocument->CreateHTMLElement(nsGkAtoms::div);
|
|
|
|
child->SetAttr(kNameSpaceID_None, nsGkAtoms::id, aElementId, true);
|
|
|
|
parent->AppendChildTo(child, false);
|
|
|
|
};
|
2015-05-04 19:25:00 +00:00
|
|
|
|
2016-08-14 12:22:04 +00:00
|
|
|
CreateAndAppendChildElement(sTextOverlayElementId);
|
2016-08-18 07:09:19 +00:00
|
|
|
CreateAndAppendChildElement(sCaretImageElementId);
|
|
|
|
CreateAndAppendChildElement(sSelectionBarElementId);
|
2015-05-04 19:25:00 +00:00
|
|
|
|
|
|
|
return parent.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AccessibleCaret::RemoveCaretElement(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
CaretElement()->RemoveEventListener(NS_LITERAL_STRING("touchstart"),
|
|
|
|
mDummyTouchListener, false);
|
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
aDocument->RemoveAnonymousContent(*mCaretElementHolder, rv);
|
|
|
|
// It's OK rv is failed since nsCanvasFrame might not exists now.
|
2015-11-20 21:29:41 +00:00
|
|
|
rv.SuppressException();
|
2015-05-04 19:25:00 +00: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.
|
2015-10-07 10:09:03 +00:00
|
|
|
mImaginaryCaretRect = nsRect();
|
2016-02-15 10:29:32 +00:00
|
|
|
mZoomLevel = 0.0f;
|
2015-05-04 19:25:00 +00:00
|
|
|
return PositionChangedResult::Invisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect imaginaryCaretRect = imaginaryCaretRectInFrame;
|
|
|
|
nsLayoutUtils::TransformRect(aFrame, RootFrame(), imaginaryCaretRect);
|
2016-02-15 10:29:32 +00:00
|
|
|
float zoomLevel = GetZoomLevel();
|
2015-05-04 19:25:00 +00:00
|
|
|
|
2016-02-15 10:29:32 +00:00
|
|
|
if (imaginaryCaretRect.IsEqualEdges(mImaginaryCaretRect) &&
|
|
|
|
FuzzyEqualsMultiplicative(zoomLevel, mZoomLevel)) {
|
2015-05-04 19:25:00 +00:00
|
|
|
return PositionChangedResult::NotChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
mImaginaryCaretRect = imaginaryCaretRect;
|
2016-02-15 10:29:32 +00:00
|
|
|
mZoomLevel = zoomLevel;
|
2015-05-04 19:25:00 +00:00
|
|
|
|
2016-08-14 12:22:04 +00:00
|
|
|
// SetCaretElementStyle() requires the input rect relative to container frame.
|
2015-05-04 19:25:00 +00:00
|
|
|
nsRect imaginaryCaretRectInContainerFrame = imaginaryCaretRectInFrame;
|
|
|
|
nsLayoutUtils::TransformRect(aFrame, CustomContentContainerFrame(),
|
|
|
|
imaginaryCaretRectInContainerFrame);
|
2016-02-15 10:29:32 +00:00
|
|
|
SetCaretElementStyle(imaginaryCaretRectInContainerFrame, mZoomLevel);
|
2015-05-04 19:25:00 +00:00
|
|
|
|
|
|
|
return PositionChangedResult::Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
AccessibleCaret::CustomContentContainerFrame() const
|
|
|
|
{
|
|
|
|
nsCanvasFrame* canvasFrame = mPresShell->GetCanvasFrame();
|
|
|
|
Element* container = canvasFrame->GetCustomContentContainer();
|
|
|
|
nsIFrame* containerFrame = container->GetPrimaryFrame();
|
|
|
|
return containerFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-02-15 10:29:32 +00:00
|
|
|
AccessibleCaret::SetCaretElementStyle(const nsRect& aRect, float aZoomLevel)
|
2015-05-04 19:25:00 +00:00
|
|
|
{
|
|
|
|
nsPoint position = CaretElementPosition(aRect);
|
|
|
|
nsAutoString styleStr;
|
2016-08-14 12:22:04 +00:00
|
|
|
styleStr.AppendPrintf("left: %dpx; top: %dpx; "
|
2017-03-15 03:16:32 +00:00
|
|
|
"width: ",
|
2015-05-04 19:25:00 +00:00
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(position.x),
|
2017-03-15 03:16:32 +00:00
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(position.y));
|
|
|
|
// We can't use AppendPrintf here, because it does locale-specific
|
|
|
|
// formatting of floating-point values.
|
|
|
|
styleStr.AppendFloat(sWidth/aZoomLevel);
|
|
|
|
styleStr.AppendLiteral("px; height: ");
|
|
|
|
styleStr.AppendFloat(sHeight/aZoomLevel);
|
|
|
|
styleStr.AppendLiteral("px; margin-left: ");
|
|
|
|
styleStr.AppendFloat(sMarginLeft/aZoomLevel);
|
|
|
|
styleStr.AppendLiteral("px");
|
2015-05-15 16:05:00 +00:00
|
|
|
|
2016-08-14 12:22:04 +00:00
|
|
|
CaretElement()->SetAttr(kNameSpaceID_None, nsGkAtoms::style, styleStr, true);
|
|
|
|
AC_LOG("%s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(styleStr).get());
|
2015-05-04 19:25:00 +00:00
|
|
|
|
2016-08-14 12:22:04 +00:00
|
|
|
// Set style string for children.
|
|
|
|
SetTextOverlayElementStyle(aRect, aZoomLevel);
|
|
|
|
SetCaretImageElementStyle(aRect, aZoomLevel);
|
|
|
|
SetSelectionBarElementStyle(aRect, aZoomLevel);
|
2015-05-04 19:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-14 12:22:04 +00:00
|
|
|
AccessibleCaret::SetTextOverlayElementStyle(const nsRect& aRect,
|
|
|
|
float aZoomLevel)
|
2015-05-04 19:25:00 +00:00
|
|
|
{
|
2016-08-14 12:22:04 +00:00
|
|
|
nsAutoString styleStr;
|
|
|
|
styleStr.AppendPrintf("height: %dpx;",
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(aRect.height));
|
|
|
|
TextOverlayElement()->SetAttr(kNameSpaceID_None, nsGkAtoms::style, styleStr,
|
|
|
|
true);
|
|
|
|
AC_LOG("%s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(styleStr).get());
|
|
|
|
}
|
2015-05-15 16:05:00 +00:00
|
|
|
|
2016-08-14 12:22:04 +00:00
|
|
|
void
|
|
|
|
AccessibleCaret::SetCaretImageElementStyle(const nsRect& aRect,
|
|
|
|
float aZoomLevel)
|
|
|
|
{
|
|
|
|
nsAutoString styleStr;
|
|
|
|
styleStr.AppendPrintf("margin-top: %dpx;",
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(aRect.height));
|
|
|
|
CaretImageElement()->SetAttr(kNameSpaceID_None, nsGkAtoms::style, styleStr,
|
|
|
|
true);
|
|
|
|
AC_LOG("%s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(styleStr).get());
|
|
|
|
}
|
2015-05-04 19:25:00 +00:00
|
|
|
|
2016-08-14 12:22:04 +00:00
|
|
|
void
|
|
|
|
AccessibleCaret::SetSelectionBarElementStyle(const nsRect& aRect,
|
|
|
|
float aZoomLevel)
|
|
|
|
{
|
|
|
|
nsAutoString styleStr;
|
2017-03-15 03:16:32 +00:00
|
|
|
styleStr.AppendPrintf("height: %dpx; width: ",
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(aRect.height));
|
|
|
|
// We can't use AppendPrintf here, because it does locale-specific
|
|
|
|
// formatting of floating-point values.
|
|
|
|
styleStr.AppendFloat(sBarWidth / aZoomLevel);
|
|
|
|
styleStr.AppendLiteral("px");
|
|
|
|
|
2016-08-14 12:22:04 +00:00
|
|
|
SelectionBarElement()->SetAttr(kNameSpaceID_None, nsGkAtoms::style, styleStr,
|
|
|
|
true);
|
|
|
|
AC_LOG("%s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(styleStr).get());
|
2015-05-04 19:25:00 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 16:05:00 +00:00
|
|
|
float
|
|
|
|
AccessibleCaret::GetZoomLevel()
|
|
|
|
{
|
|
|
|
// Full zoom on desktop.
|
|
|
|
float fullZoom = mPresShell->GetPresContext()->GetFullZoom();
|
|
|
|
|
2017-04-20 05:16:42 +00:00
|
|
|
// Pinch-zoom on fennec.
|
2015-05-15 16:05:00 +00:00
|
|
|
float resolution = mPresShell->GetCumulativeResolution();
|
|
|
|
|
|
|
|
return fullZoom * resolution;
|
|
|
|
}
|
|
|
|
|
2015-05-04 19:25:00 +00:00
|
|
|
} // namespace mozilla
|