Bug 1336388 - Use overlapping tilt mechanism in always tilt mode. r=mtseng

MozReview-Commit-ID: LwWnAbHiTBH

--HG--
extra : rebase_source : fb71526b2205edcaa40c5f6d2ace863ad7831a2a
This commit is contained in:
Ting-Yu Lin 2017-02-08 15:51:28 +08:00
parent 3d19c8f732
commit 723732ff7f
3 changed files with 29 additions and 17 deletions

View File

@ -429,30 +429,41 @@ AccessibleCaretManager::UpdateCaretsForSelectionMode(UpdateCaretsHint aHint)
}
}
void
bool
AccessibleCaretManager::UpdateCaretsForOverlappingTilt()
{
if (mFirstCaret->IsVisuallyVisible() && mSecondCaret->IsVisuallyVisible()) {
if (mFirstCaret->Intersects(*mSecondCaret)) {
if (mFirstCaret->LogicalPosition().x <=
mSecondCaret->LogicalPosition().x) {
mFirstCaret->SetAppearance(Appearance::Left);
mSecondCaret->SetAppearance(Appearance::Right);
} else {
mFirstCaret->SetAppearance(Appearance::Right);
mSecondCaret->SetAppearance(Appearance::Left);
}
} else {
mFirstCaret->SetAppearance(Appearance::Normal);
mSecondCaret->SetAppearance(Appearance::Normal);
}
if (!mFirstCaret->IsVisuallyVisible() || !mSecondCaret->IsVisuallyVisible()) {
return false;
}
if (!mFirstCaret->Intersects(*mSecondCaret)) {
mFirstCaret->SetAppearance(Appearance::Normal);
mSecondCaret->SetAppearance(Appearance::Normal);
return false;
}
if (mFirstCaret->LogicalPosition().x <=
mSecondCaret->LogicalPosition().x) {
mFirstCaret->SetAppearance(Appearance::Left);
mSecondCaret->SetAppearance(Appearance::Right);
} else {
mFirstCaret->SetAppearance(Appearance::Right);
mSecondCaret->SetAppearance(Appearance::Left);
}
return true;
}
void
AccessibleCaretManager::UpdateCaretsForAlwaysTilt(nsIFrame* aStartFrame,
nsIFrame* aEndFrame)
{
// When a short LTR word in RTL environment is selected, the two carets
// tilted inward might be overlapped. Make them tilt outward.
if (UpdateCaretsForOverlappingTilt()) {
return;
}
if (mFirstCaret->IsVisuallyVisible()) {
auto startFrameWritingMode = aStartFrame->GetWritingMode();
mFirstCaret->SetAppearance(startFrameWritingMode.IsBidiLTR() ?

View File

@ -226,7 +226,8 @@ protected:
nsIFrame* aEndFrame) const;
// Check if the two carets is overlapping to become tilt.
virtual void UpdateCaretsForOverlappingTilt();
// @return true if the two carets become tilt; false, otherwise.
virtual bool UpdateCaretsForOverlappingTilt();
// Make the two carets always tilt.
virtual void UpdateCaretsForAlwaysTilt(nsIFrame* aStartFrame,

View File

@ -92,7 +92,7 @@ public:
return true;
}
virtual void UpdateCaretsForOverlappingTilt() override {}
virtual bool UpdateCaretsForOverlappingTilt() override { return true; }
virtual void UpdateCaretsForAlwaysTilt(nsIFrame* aStartFrame,
nsIFrame* aEndFrame)