mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
6cfd64d931
- Bug 1195173 - Test asyncopen2 security checks for stylesheets (r=bz,ehsan) (358ae850a4) - Bug 1223644 - Clean up the nsSVGClipPathFrame reference loop detection code. r=longsonr (65042c3148) - Bug 1157064 - font-display descriptor parsing. r=dbaron (18f63d9244) - Bug 1242523 - Guard against GetWidget getting called with a null shell. r=snorp (55de891c6c) - Bug 1247679, part 3 - Replace NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK with JS_MEMBER. r=smaug (09435e582c) - Bug 1247515 - Check nsScriptErrorWithStack's mStack member for null before tracing; r=mccr8 (0cb1e09aa9) - Bug 1178803. Fix the handling of the 'length' key in IDB keypaths when operating on a string. r=bent (69f15272a8) - Bug 1201037 - coalesce network-events on Windows, r=mcmanus (5f48aab5c3) - Bug 1131626, fix autoscroll tests to work in e10s, r=felipe (c47adbaa10) - Bug 1231529 - Increase the timeout of browser_bug295977_autoscroll_overflow.js (691d27224d) - Bug 416611 - Changed BookmarkHTMLUtils.jsm to import bookmark tags from HTML document. r=mak (49a0accc13) - Bug 1130858 - Recipient autocomplete suggestion overrides ANY manual address input if quickly entered/pasted and confirmed with Enter/Tab before autocomplete suggestions disappear. r=mak (308196e116) - Bug 1197361. Optimize page thumbnails based on screen size. r=ttaubert (29dca20366) - Bug 555087 - Add check for exception when passing undefined parameter. r=adw (3588477c56) - Bug 1203803: Force cleanup for specific states only; r=khuey a=CLOSED TREE (2f9f78ad72) - Bug 1203803 - Remove forced cleanup from FactoryOp::ActorDestroy() since it cause more harm than good; r=khuey (76a00e58cb) - Bug 1195149 - Upgrade the check to a MOZ_RELEASE_ASSERT. r=janv (071d1fc267) - Bug 1185223 - crash at [@ mozilla::dom::quota::QuotaObject::Release() ]; r=khuey (d460972a45) - Bug 1229376 - Downgrade lastVacuumSize > 0 assertion to an NS_ASSERTION so we don't have to star it all over the place, rs=khuey (81d715ab71) - Bug 1239666 - part 1, get rid of the default parameter. r=waldo (639fb79ec3) - Bug 1239666 - part 2, dom/indexedDB change. r=khuey (6faaf25df4) - Bug 1239666 - part 3, devtools test case changes. r=sphink (c010d06a77) - Bug 1248309 - Fix caret size not updated when only zoom level is changed. r=roc (91cc5b35df) - Bug 1245649: Turn on no-trailing-spaces. r=Gijs (7f87c967af) - Bug 1245649: Enable no-negated-in-lhs, no-native-reassign, no-func-assign and no-labels. r=MattN (5f801e4a4c) - Bug 1197966 - Fix typo when releasing content-side probes in PerformanceStats-content.js. r=felipe (9241324efd) - Bug 1219144 - Performance alerts are now labelled with isJankVisible; r=avih,froydnj (c1549a24f5) - Bug 1219144 - Using the nsRefreshDriver's jank indication for performance monitoring;f?froydnj r=froydnj (735c6fba9c) - Bug 1211783 - Add KeyframeEffect interface to dom/webidl/KeyframeEffect.webidl. r=smaug,birtles (fca332fea0) - Bug 795681 - Print out failures in mozunit runner. r=gps (ce418e5ea8) - Bug 801679 - Handle expected failures and skipped tests in mozunit runner. r=gps (396ca02893) - Bug 1247833 - Display the class name in mozunit output. r=gps (0b5724f41c) - Bug 1245022 - Kill stlport's Makefile.in. r=mshal (225f662efc) - Bug 1194603 - Remove INTERNAL_TOOLS; r=mshal (e8e90ec1c3) - Bug 1247743 - Expose non-pinning JS_Atomize[UC]String JSAPI functions; r=terrence (66aa23066d) - Bug 1230071 - Enable warnings-as-errors in js/src. r=Waldo (a0c8acf6ad) - Bug 1007136 - Ensure malloc/free always match when using JSAutoByteString; r=bz (81dfcf036a) - Bug 1246850 - check the NotifyIpInterfaceChange() return code, r=mcmanus (bc224f287c) - Bug 739029 - null check a thread allocation in notifyaddrlistener r=bagder (ce0ddfc44c)
349 lines
11 KiB
C++
349 lines
11 KiB
C++
/* -*- 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"
|
|
#include "mozilla/FloatingPoint.h"
|
|
#include "mozilla/Preferences.h"
|
|
#include "mozilla/ToString.h"
|
|
#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)
|
|
|
|
float AccessibleCaret::sWidth = 0.0f;
|
|
float AccessibleCaret::sHeight = 0.0f;
|
|
float AccessibleCaret::sMarginLeft = 0.0f;
|
|
float AccessibleCaret::sBarWidth = 0.0f;
|
|
|
|
#define AC_PROCESS_ENUM_TO_STREAM(e) case(e): aStream << #e; break;
|
|
std::ostream&
|
|
operator<<(std::ostream& aStream, const AccessibleCaret::Appearance& aAppearance)
|
|
{
|
|
using Appearance = AccessibleCaret::Appearance;
|
|
switch (aAppearance) {
|
|
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);
|
|
}
|
|
return aStream;
|
|
}
|
|
|
|
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);
|
|
}
|
|
return aStream;
|
|
}
|
|
#undef AC_PROCESS_ENUM_TO_STREAM
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Implementation of AccessibleCaret methods
|
|
|
|
AccessibleCaret::AccessibleCaret(nsIPresShell* aPresShell)
|
|
: mPresShell(aPresShell)
|
|
{
|
|
// Check all resources required.
|
|
if (mPresShell) {
|
|
MOZ_ASSERT(RootFrame());
|
|
MOZ_ASSERT(mPresShell->GetDocument());
|
|
MOZ_ASSERT(mPresShell->GetCanvasFrame());
|
|
MOZ_ASSERT(mPresShell->GetCanvasFrame()->GetCustomContentContainer());
|
|
|
|
InjectCaretElement(mPresShell->GetDocument());
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
AccessibleCaret::~AccessibleCaret()
|
|
{
|
|
if (mPresShell) {
|
|
RemoveCaretElement(mPresShell->GetDocument());
|
|
}
|
|
}
|
|
|
|
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!");
|
|
|
|
AC_LOG("%s: %s -> %s", __FUNCTION__, ToString(mAppearance).c_str(),
|
|
ToString(aAppearance).c_str());
|
|
|
|
mAppearance = aAppearance;
|
|
|
|
// Need to reset rect since the cached rect will be compared in SetPosition.
|
|
if (mAppearance == Appearance::None) {
|
|
mImaginaryCaretRect = nsRect();
|
|
mZoomLevel = 0.0f;
|
|
}
|
|
}
|
|
|
|
void
|
|
AccessibleCaret::SetSelectionBarEnabled(bool aEnabled)
|
|
{
|
|
if (mSelectionBarEnabled == aEnabled) {
|
|
return;
|
|
}
|
|
|
|
AC_LOG("Set selection bar %s", aEnabled ? "Enabled" : "Disabled");
|
|
|
|
ErrorResult rv;
|
|
CaretElement()->ClassList()->Toggle(NS_LITERAL_STRING("no-bar"),
|
|
Optional<bool>(!aEnabled), rv);
|
|
MOZ_ASSERT(!rv.Failed());
|
|
|
|
mSelectionBarEnabled = aEnabled;
|
|
}
|
|
|
|
/* static */ nsString
|
|
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
|
|
AccessibleCaret::Contains(const nsPoint& aPoint) const
|
|
{
|
|
if (!IsVisuallyVisible()) {
|
|
return false;
|
|
}
|
|
|
|
nsRect rect =
|
|
nsLayoutUtils::GetRectRelativeToFrame(CaretImageElement(), RootFrame());
|
|
|
|
return rect.Contains(aPoint);
|
|
}
|
|
|
|
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.
|
|
CaretElement()->AddEventListener(NS_LITERAL_STRING("touchstart"),
|
|
mDummyTouchListener, false);
|
|
}
|
|
|
|
already_AddRefed<Element>
|
|
AccessibleCaret::CreateCaretElement(nsIDocument* aDocument) const
|
|
{
|
|
// Content structure of AccessibleCaret
|
|
// <div class="moz-accessiblecaret"> <- CaretElement()
|
|
// <div class="image"> <- CaretImageElement()
|
|
// <div class="bar"> <- SelectionBarElement()
|
|
|
|
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);
|
|
|
|
nsCOMPtr<Element> image = aDocument->CreateHTMLElement(nsGkAtoms::div);
|
|
image->ClassList()->Add(NS_LITERAL_STRING("image"), rv);
|
|
parent->AppendChildTo(image, false);
|
|
|
|
nsCOMPtr<Element> bar = aDocument->CreateHTMLElement(nsGkAtoms::div);
|
|
bar->ClassList()->Add(NS_LITERAL_STRING("bar"), rv);
|
|
parent->AppendChildTo(bar, false);
|
|
|
|
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.
|
|
rv.SuppressException();
|
|
}
|
|
|
|
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.
|
|
mImaginaryCaretRect = nsRect();
|
|
mZoomLevel = 0.0f;
|
|
return PositionChangedResult::Invisible;
|
|
}
|
|
|
|
nsRect imaginaryCaretRect = imaginaryCaretRectInFrame;
|
|
nsLayoutUtils::TransformRect(aFrame, RootFrame(), imaginaryCaretRect);
|
|
float zoomLevel = GetZoomLevel();
|
|
|
|
if (imaginaryCaretRect.IsEqualEdges(mImaginaryCaretRect) &&
|
|
FuzzyEqualsMultiplicative(zoomLevel, mZoomLevel)) {
|
|
return PositionChangedResult::NotChanged;
|
|
}
|
|
|
|
mImaginaryCaretRect = imaginaryCaretRect;
|
|
mZoomLevel = zoomLevel;
|
|
|
|
// SetCaretElementStyle() and SetSelectionBarElementStyle() require the
|
|
// input rect relative to container frame.
|
|
nsRect imaginaryCaretRectInContainerFrame = imaginaryCaretRectInFrame;
|
|
nsLayoutUtils::TransformRect(aFrame, CustomContentContainerFrame(),
|
|
imaginaryCaretRectInContainerFrame);
|
|
SetCaretElementStyle(imaginaryCaretRectInContainerFrame, mZoomLevel);
|
|
SetSelectionBarElementStyle(imaginaryCaretRectInContainerFrame, mZoomLevel);
|
|
|
|
return PositionChangedResult::Changed;
|
|
}
|
|
|
|
nsIFrame*
|
|
AccessibleCaret::CustomContentContainerFrame() const
|
|
{
|
|
nsCanvasFrame* canvasFrame = mPresShell->GetCanvasFrame();
|
|
Element* container = canvasFrame->GetCustomContentContainer();
|
|
nsIFrame* containerFrame = container->GetPrimaryFrame();
|
|
return containerFrame;
|
|
}
|
|
|
|
void
|
|
AccessibleCaret::SetCaretElementStyle(const nsRect& aRect, float aZoomLevel)
|
|
{
|
|
nsPoint position = CaretElementPosition(aRect);
|
|
nsAutoString styleStr;
|
|
styleStr.AppendPrintf("left: %dpx; top: %dpx; padding-top: %dpx;",
|
|
nsPresContext::AppUnitsToIntCSSPixels(position.x),
|
|
nsPresContext::AppUnitsToIntCSSPixels(position.y),
|
|
nsPresContext::AppUnitsToIntCSSPixels(aRect.height));
|
|
|
|
styleStr.AppendPrintf(" width: %.2fpx; height: %.2fpx; margin-left: %.2fpx",
|
|
sWidth / aZoomLevel,
|
|
sHeight / aZoomLevel,
|
|
sMarginLeft / aZoomLevel);
|
|
|
|
ErrorResult rv;
|
|
CaretElement()->SetAttribute(NS_LITERAL_STRING("style"), styleStr, rv);
|
|
MOZ_ASSERT(!rv.Failed());
|
|
|
|
AC_LOG("Set caret style: %s", NS_ConvertUTF16toUTF8(styleStr).get());
|
|
}
|
|
|
|
void
|
|
AccessibleCaret::SetSelectionBarElementStyle(const nsRect& aRect,
|
|
float aZoomLevel)
|
|
{
|
|
int32_t height = nsPresContext::AppUnitsToIntCSSPixels(aRect.height);
|
|
nsAutoString barStyleStr;
|
|
barStyleStr.AppendPrintf("margin-top: -%dpx; height: %dpx;",
|
|
height, height);
|
|
|
|
barStyleStr.AppendPrintf(" width: %.2fpx;", sBarWidth / aZoomLevel);
|
|
|
|
ErrorResult rv;
|
|
SelectionBarElement()->SetAttribute(NS_LITERAL_STRING("style"), barStyleStr, rv);
|
|
MOZ_ASSERT(!rv.Failed());
|
|
|
|
AC_LOG("Set bar style: %s", NS_ConvertUTF16toUTF8(barStyleStr).get());
|
|
}
|
|
|
|
float
|
|
AccessibleCaret::GetZoomLevel()
|
|
{
|
|
// Full zoom on desktop.
|
|
float fullZoom = mPresShell->GetPresContext()->GetFullZoom();
|
|
|
|
// Pinch-zoom on B2G or fennec.
|
|
float resolution = mPresShell->GetCumulativeResolution();
|
|
|
|
return fullZoom * resolution;
|
|
}
|
|
|
|
} // namespace mozilla
|