2017-10-27 20:33:53 +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: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
1999-02-12 02:49:08 +03:00
|
|
|
|
2006-03-30 09:56:38 +04:00
|
|
|
/* the caret is the text cursor used, e.g., when editing */
|
1999-02-12 02:49:08 +03:00
|
|
|
|
2014-08-06 09:19:30 +04:00
|
|
|
#include "nsCaret.h"
|
1999-02-12 02:49:08 +03:00
|
|
|
|
2014-08-06 09:19:30 +04:00
|
|
|
#include <algorithm>
|
1999-02-12 02:49:08 +03:00
|
|
|
|
2014-10-19 16:22:22 +04:00
|
|
|
#include "gfxUtils.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
2014-08-06 09:19:30 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2014-10-24 19:28:14 +04:00
|
|
|
#include "nsFontMetrics.h"
|
2014-08-06 09:19:30 +04:00
|
|
|
#include "nsITimer.h"
|
2006-04-26 05:57:22 +04:00
|
|
|
#include "nsFrameSelection.h"
|
1999-02-12 02:49:08 +03:00
|
|
|
#include "nsIFrame.h"
|
2007-08-14 00:51:16 +04:00
|
|
|
#include "nsIScrollableFrame.h"
|
1999-02-12 02:49:08 +03:00
|
|
|
#include "nsIDOMNode.h"
|
2000-09-14 15:45:01 +04:00
|
|
|
#include "nsISelection.h"
|
|
|
|
#include "nsISelectionPrivate.h"
|
1999-02-12 02:49:08 +03:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIPresShell.h"
|
2014-10-19 16:22:22 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1999-09-15 03:41:19 +04:00
|
|
|
#include "nsBlockFrame.h"
|
2000-04-27 11:37:12 +04:00
|
|
|
#include "nsISelectionController.h"
|
2007-11-08 07:07:00 +03:00
|
|
|
#include "nsTextFrame.h"
|
2008-04-01 12:35:11 +04:00
|
|
|
#include "nsXULPopupManager.h"
|
|
|
|
#include "nsMenuPopupFrame.h"
|
2008-04-23 07:13:55 +04:00
|
|
|
#include "nsTextFragment.h"
|
2011-05-25 10:31:59 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-09-09 06:27:13 +04:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2006-08-08 09:14:52 +04:00
|
|
|
#include "nsIBidiKeyboard.h"
|
|
|
|
#include "nsContentUtils.h"
|
2001-03-21 04:16:22 +03:00
|
|
|
|
2011-05-25 10:31:59 +04:00
|
|
|
using namespace mozilla;
|
2014-08-06 09:19:27 +04:00
|
|
|
using namespace mozilla::dom;
|
2014-10-19 16:22:22 +04:00
|
|
|
using namespace mozilla::gfx;
|
2011-05-25 10:31:59 +04:00
|
|
|
|
2014-08-06 09:19:30 +04:00
|
|
|
// The bidi indicator hangs off the caret to one side, to show which
|
2017-07-06 15:00:35 +03:00
|
|
|
// direction the typing is in. It needs to be at least 2x2 to avoid looking like
|
2014-08-06 09:19:30 +04:00
|
|
|
// an insignificant dot
|
|
|
|
static const int32_t kMinBidiIndicatorPixels = 2;
|
|
|
|
|
2017-06-14 03:09:22 +03:00
|
|
|
// The default caret blinking rate (in ms of blinking interval)
|
|
|
|
static const uint32_t kDefaultCaretBlinkRate = 500;
|
|
|
|
|
2010-03-15 01:52:45 +03:00
|
|
|
/**
|
|
|
|
* Find the first frame in an in-order traversal of the frame subtree rooted
|
|
|
|
* at aFrame which is either a text frame logically at the end of a line,
|
|
|
|
* or which is aStopAtFrame. Return null if no such frame is found. We don't
|
|
|
|
* descend into the children of non-eLineParticipant frames.
|
|
|
|
*/
|
|
|
|
static nsIFrame*
|
|
|
|
CheckForTrailingTextFrameRecursive(nsIFrame* aFrame, nsIFrame* aStopAtFrame)
|
|
|
|
{
|
|
|
|
if (aFrame == aStopAtFrame ||
|
2017-04-30 18:30:08 +03:00
|
|
|
((aFrame->IsTextFrame() &&
|
2010-03-15 01:52:45 +03:00
|
|
|
(static_cast<nsTextFrame*>(aFrame))->IsAtEndOfLine())))
|
|
|
|
return aFrame;
|
|
|
|
if (!aFrame->IsFrameOfType(nsIFrame::eLineParticipant))
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-03-15 01:52:45 +03:00
|
|
|
|
2016-01-29 17:42:15 +03:00
|
|
|
for (nsIFrame* f : aFrame->PrincipalChildList())
|
2010-03-15 01:52:45 +03:00
|
|
|
{
|
|
|
|
nsIFrame* r = CheckForTrailingTextFrameRecursive(f, aStopAtFrame);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-03-15 01:52:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsLineBox*
|
|
|
|
FindContainingLine(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
while (aFrame && aFrame->IsFrameOfType(nsIFrame::eLineParticipant))
|
|
|
|
{
|
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
|
|
|
nsBlockFrame* blockParent = nsLayoutUtils::GetAsBlock(parent);
|
|
|
|
if (blockParent)
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isValid;
|
2010-03-15 01:52:45 +03:00
|
|
|
nsBlockInFlowLineIterator iter(blockParent, aFrame, &isValid);
|
2012-07-30 18:20:58 +04:00
|
|
|
return isValid ? iter.GetLine().get() : nullptr;
|
2010-03-15 01:52:45 +03:00
|
|
|
}
|
|
|
|
aFrame = parent;
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-03-15 01:52:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-22 19:56:38 +04:00
|
|
|
AdjustCaretFrameForLineEnd(nsIFrame** aFrame, int32_t* aOffset)
|
2010-03-15 01:52:45 +03:00
|
|
|
{
|
|
|
|
nsLineBox* line = FindContainingLine(*aFrame);
|
|
|
|
if (!line)
|
|
|
|
return;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = line->GetChildCount();
|
2010-03-15 01:52:45 +03:00
|
|
|
for (nsIFrame* f = line->mFirstChild; count > 0; --count, f = f->GetNextSibling())
|
|
|
|
{
|
|
|
|
nsIFrame* r = CheckForTrailingTextFrameRecursive(f, *aFrame);
|
|
|
|
if (r == *aFrame)
|
|
|
|
return;
|
|
|
|
if (r)
|
|
|
|
{
|
|
|
|
*aFrame = r;
|
2017-04-30 18:30:08 +03:00
|
|
|
NS_ASSERTION(r->IsTextFrame(), "Expected text frame");
|
2010-03-15 01:52:45 +03:00
|
|
|
*aOffset = (static_cast<nsTextFrame*>(r))->GetContentEnd();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 1048752. Part 22: Factor out SelectionLanguageChange call to run early in nsCaret::GetPaintGeometry. r=tn
This code is somewhat tricky. nsCaret::ComputeCaretRects was checking to see
if we have a bidi keyboard, and if so, what direction it's set to.
If the direction changed from the last direction seen for *this caret*,
we fired a SelectionLanguageChange notification on the caret's current
Selection. This looked bogus because the caret can be switched between
selections so it would seem some selections won't get a notification when
they should, but that's how it was. Also, when the SelectionLanguageChange
notification fired we then didn't draw the caret in that iteration, which
seems even more bogus.
This patch fixes all that by moving the logic to fire SelectionLanguageChange
out to GetPaintGeometry and firing the notification every single time without
trying to detect whether the state has changed or not. I carefully examined
the implementation of SelectionLanguageChange and I'm pretty sure it's
idempotent so this should be correct. That doesn't look like an
expensive function, and runs at most once per window paint, so I'm not
worried about perf. Because we now fire SelectionLanguageChange before
reading selection or frame state, it should be fine to carry on after
calling SelectionLanguageChange and drawing the caret based on whatever
changes SelectionLanguageChange has performed.
This also lets us remove mKeyboardRTL, which as noted above seems inherently
bogus.
--HG--
extra : rebase_source : 3ddfd10f6f30033e090e72b4bb43f2695218752e
2014-08-06 09:19:28 +04:00
|
|
|
static bool
|
2015-11-10 15:42:23 +03:00
|
|
|
IsBidiUI()
|
Bug 1048752. Part 22: Factor out SelectionLanguageChange call to run early in nsCaret::GetPaintGeometry. r=tn
This code is somewhat tricky. nsCaret::ComputeCaretRects was checking to see
if we have a bidi keyboard, and if so, what direction it's set to.
If the direction changed from the last direction seen for *this caret*,
we fired a SelectionLanguageChange notification on the caret's current
Selection. This looked bogus because the caret can be switched between
selections so it would seem some selections won't get a notification when
they should, but that's how it was. Also, when the SelectionLanguageChange
notification fired we then didn't draw the caret in that iteration, which
seems even more bogus.
This patch fixes all that by moving the logic to fire SelectionLanguageChange
out to GetPaintGeometry and firing the notification every single time without
trying to detect whether the state has changed or not. I carefully examined
the implementation of SelectionLanguageChange and I'm pretty sure it's
idempotent so this should be correct. That doesn't look like an
expensive function, and runs at most once per window paint, so I'm not
worried about perf. Because we now fire SelectionLanguageChange before
reading selection or frame state, it should be fine to carry on after
calling SelectionLanguageChange and drawing the caret based on whatever
changes SelectionLanguageChange has performed.
This also lets us remove mKeyboardRTL, which as noted above seems inherently
bogus.
--HG--
extra : rebase_source : 3ddfd10f6f30033e090e72b4bb43f2695218752e
2014-08-06 09:19:28 +04:00
|
|
|
{
|
2015-11-10 15:42:23 +03:00
|
|
|
return Preferences::GetBool("bidi.browser.ui");
|
Bug 1048752. Part 22: Factor out SelectionLanguageChange call to run early in nsCaret::GetPaintGeometry. r=tn
This code is somewhat tricky. nsCaret::ComputeCaretRects was checking to see
if we have a bidi keyboard, and if so, what direction it's set to.
If the direction changed from the last direction seen for *this caret*,
we fired a SelectionLanguageChange notification on the caret's current
Selection. This looked bogus because the caret can be switched between
selections so it would seem some selections won't get a notification when
they should, but that's how it was. Also, when the SelectionLanguageChange
notification fired we then didn't draw the caret in that iteration, which
seems even more bogus.
This patch fixes all that by moving the logic to fire SelectionLanguageChange
out to GetPaintGeometry and firing the notification every single time without
trying to detect whether the state has changed or not. I carefully examined
the implementation of SelectionLanguageChange and I'm pretty sure it's
idempotent so this should be correct. That doesn't look like an
expensive function, and runs at most once per window paint, so I'm not
worried about perf. Because we now fire SelectionLanguageChange before
reading selection or frame state, it should be fine to carry on after
calling SelectionLanguageChange and drawing the caret based on whatever
changes SelectionLanguageChange has performed.
This also lets us remove mKeyboardRTL, which as noted above seems inherently
bogus.
--HG--
extra : rebase_source : 3ddfd10f6f30033e090e72b4bb43f2695218752e
2014-08-06 09:19:28 +04:00
|
|
|
}
|
|
|
|
|
1999-02-12 02:49:08 +03:00
|
|
|
nsCaret::nsCaret()
|
2014-08-06 09:19:30 +04:00
|
|
|
: mOverrideOffset(0)
|
2015-04-29 17:23:19 +03:00
|
|
|
, mBlinkCount(-1)
|
2017-06-14 03:09:22 +03:00
|
|
|
, mBlinkRate(0)
|
2015-08-17 14:58:38 +03:00
|
|
|
, mHideCount(0)
|
|
|
|
, mIsBlinkOn(false)
|
2011-10-17 18:59:28 +04:00
|
|
|
, mVisible(false)
|
|
|
|
, mReadOnly(false)
|
|
|
|
, mShowDuringSelection(false)
|
|
|
|
, mIgnoreUserModify(true)
|
1999-02-12 02:49:08 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCaret::~nsCaret()
|
|
|
|
{
|
2014-08-06 09:19:30 +04:00
|
|
|
StopBlinking();
|
1999-02-12 02:49:08 +03:00
|
|
|
}
|
|
|
|
|
2008-07-16 14:52:01 +04:00
|
|
|
nsresult nsCaret::Init(nsIPresShell *inPresShell)
|
1999-02-12 02:49:08 +03:00
|
|
|
{
|
2003-02-28 02:09:51 +03:00
|
|
|
NS_ENSURE_ARG(inPresShell);
|
2008-07-16 14:52:01 +04:00
|
|
|
|
2003-07-25 23:06:59 +04:00
|
|
|
mPresShell = do_GetWeakReference(inPresShell); // the presshell owns us, so no addref
|
2003-02-28 02:09:51 +03:00
|
|
|
NS_ASSERTION(mPresShell, "Hey, pres shell should support weak refs");
|
2000-04-27 11:37:12 +04:00
|
|
|
|
2011-09-09 06:27:13 +04:00
|
|
|
mShowDuringSelection =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_ShowCaretDuringSelection,
|
|
|
|
mShowDuringSelection ? 1 : 0) != 0;
|
|
|
|
|
2000-09-07 09:26:25 +04:00
|
|
|
// get the selection from the pres shell, and set ourselves up as a selection
|
|
|
|
// listener
|
2003-02-28 02:09:51 +03:00
|
|
|
|
2000-04-27 11:37:12 +04:00
|
|
|
nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mPresShell);
|
2003-02-28 02:09:51 +03:00
|
|
|
if (!selCon)
|
2000-04-27 11:37:12 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2003-02-28 02:09:51 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> domSelection;
|
2006-04-18 03:16:46 +04:00
|
|
|
nsresult rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
|
|
|
getter_AddRefs(domSelection));
|
2003-02-28 02:09:51 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
if (!domSelection)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelectionPrivate> privateSelection = do_QueryInterface(domSelection);
|
|
|
|
if (privateSelection)
|
|
|
|
privateSelection->AddSelectionListener(this);
|
2003-07-25 23:06:59 +04:00
|
|
|
mDomSelectionWeak = do_GetWeakReference(domSelection);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2000-09-07 09:26:25 +04:00
|
|
|
return NS_OK;
|
1999-02-12 02:49:08 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2012-08-22 19:56:38 +04:00
|
|
|
DrawCJKCaret(nsIFrame* aFrame, int32_t aOffset)
|
2008-04-23 07:13:55 +04:00
|
|
|
{
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
const nsTextFragment* frag = content->GetText();
|
|
|
|
if (!frag)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2012-08-22 19:56:38 +04:00
|
|
|
if (aOffset < 0 || uint32_t(aOffset) >= frag->GetLength())
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t ch = frag->CharAt(aOffset);
|
2008-04-23 07:13:55 +04:00
|
|
|
return 0x2e80 <= ch && ch <= 0xd7ff;
|
|
|
|
}
|
|
|
|
|
2014-08-06 09:19:29 +04:00
|
|
|
nsCaret::Metrics
|
|
|
|
nsCaret::ComputeMetrics(nsIFrame* aFrame, int32_t aOffset, nscoord aCaretHeight)
|
2008-04-15 01:09:23 +04:00
|
|
|
{
|
|
|
|
// Compute nominal sizes in appunits
|
2014-08-06 09:19:25 +04:00
|
|
|
nscoord caretWidth =
|
|
|
|
(aCaretHeight * LookAndFeel::GetFloat(LookAndFeel::eFloatID_CaretAspectRatio, 0.0f)) +
|
2014-08-06 09:19:25 +04:00
|
|
|
nsPresContext::CSSPixelsToAppUnits(
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_CaretWidth, 1));
|
2008-06-23 12:50:52 +04:00
|
|
|
|
2008-04-23 07:13:55 +04:00
|
|
|
if (DrawCJKCaret(aFrame, aOffset)) {
|
|
|
|
caretWidth += nsPresContext::CSSPixelsToAppUnits(1);
|
|
|
|
}
|
2008-04-15 01:09:23 +04:00
|
|
|
nscoord bidiIndicatorSize = nsPresContext::CSSPixelsToAppUnits(kMinBidiIndicatorPixels);
|
2013-01-15 16:22:03 +04:00
|
|
|
bidiIndicatorSize = std::max(caretWidth, bidiIndicatorSize);
|
2008-04-15 01:09:23 +04:00
|
|
|
|
|
|
|
// Round them to device pixels. Always round down, except that anything
|
|
|
|
// between 0 and 1 goes up to 1 so we don't let the caret disappear.
|
2013-02-20 01:46:27 +04:00
|
|
|
int32_t tpp = aFrame->PresContext()->AppUnitsPerDevPixel();
|
2008-04-15 01:09:23 +04:00
|
|
|
Metrics result;
|
|
|
|
result.mCaretWidth = NS_ROUND_BORDER_TO_PIXELS(caretWidth, tpp);
|
|
|
|
result.mBidiIndicatorSize = NS_ROUND_BORDER_TO_PIXELS(bidiIndicatorSize, tpp);
|
|
|
|
return result;
|
|
|
|
}
|
1999-02-12 02:49:08 +03:00
|
|
|
|
2008-07-16 14:52:01 +04:00
|
|
|
void nsCaret::Terminate()
|
1999-02-12 02:49:08 +03:00
|
|
|
{
|
2006-04-18 03:16:46 +04:00
|
|
|
// this doesn't erase the caret if it's drawn. Should it? We might not have
|
|
|
|
// a good drawing environment during teardown.
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2014-08-06 09:19:30 +04:00
|
|
|
StopBlinking();
|
2012-07-30 18:20:58 +04:00
|
|
|
mBlinkTimer = nullptr;
|
2000-09-14 15:45:01 +04:00
|
|
|
|
2003-02-28 02:09:51 +03:00
|
|
|
// unregiser ourselves as a selection listener
|
|
|
|
nsCOMPtr<nsISelection> domSelection = do_QueryReferent(mDomSelectionWeak);
|
|
|
|
nsCOMPtr<nsISelectionPrivate> privateSelection(do_QueryInterface(domSelection));
|
|
|
|
if (privateSelection)
|
|
|
|
privateSelection->RemoveSelectionListener(this);
|
2012-07-30 18:20:58 +04:00
|
|
|
mDomSelectionWeak = nullptr;
|
|
|
|
mPresShell = nullptr;
|
2000-09-07 09:26:25 +04:00
|
|
|
|
2014-08-06 09:19:30 +04:00
|
|
|
mOverrideContent = nullptr;
|
2003-02-28 02:09:51 +03:00
|
|
|
}
|
2000-09-07 09:26:25 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsCaret, nsISelectionListener)
|
1999-02-12 02:49:08 +03:00
|
|
|
|
2014-08-06 09:19:27 +04:00
|
|
|
nsISelection* nsCaret::GetSelection()
|
2002-09-26 04:07:53 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISelection> sel(do_QueryReferent(mDomSelectionWeak));
|
2014-08-06 09:19:27 +04:00
|
|
|
return sel;
|
2002-09-26 04:07:53 +04:00
|
|
|
}
|
|
|
|
|
2014-08-06 09:19:27 +04:00
|
|
|
void nsCaret::SetSelection(nsISelection *aDOMSel)
|
1999-02-12 02:49:08 +03:00
|
|
|
{
|
2014-08-06 09:19:27 +04:00
|
|
|
MOZ_ASSERT(aDOMSel);
|
2003-07-25 23:06:59 +04:00
|
|
|
mDomSelectionWeak = do_GetWeakReference(aDOMSel); // weak reference to pres shell
|
2014-08-06 09:19:30 +04:00
|
|
|
ResetBlinking();
|
2017-08-15 05:31:32 +03:00
|
|
|
SchedulePaint(aDOMSel);
|
2000-06-01 06:37:40 +04:00
|
|
|
}
|
|
|
|
|
2014-08-06 09:19:29 +04:00
|
|
|
void nsCaret::SetVisible(bool inMakeVisible)
|
2000-06-01 06:37:40 +04:00
|
|
|
{
|
2000-09-07 09:26:25 +04:00
|
|
|
mVisible = inMakeVisible;
|
2014-08-06 09:19:30 +04:00
|
|
|
mIgnoreUserModify = mVisible;
|
|
|
|
ResetBlinking();
|
2014-08-06 09:19:29 +04:00
|
|
|
SchedulePaint();
|
1999-02-12 02:49:08 +03:00
|
|
|
}
|
|
|
|
|
2015-08-17 14:58:38 +03:00
|
|
|
void nsCaret::AddForceHide()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mHideCount < UINT32_MAX);
|
|
|
|
if (++mHideCount > 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ResetBlinking();
|
|
|
|
SchedulePaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCaret::RemoveForceHide()
|
|
|
|
{
|
|
|
|
if (!mHideCount || --mHideCount) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ResetBlinking();
|
|
|
|
SchedulePaint();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
void nsCaret::SetCaretReadOnly(bool inMakeReadonly)
|
1999-02-12 02:49:08 +03:00
|
|
|
{
|
2000-09-07 09:26:25 +04:00
|
|
|
mReadOnly = inMakeReadonly;
|
2014-08-06 09:19:30 +04:00
|
|
|
ResetBlinking();
|
2014-08-06 09:19:29 +04:00
|
|
|
SchedulePaint();
|
1999-02-12 02:49:08 +03:00
|
|
|
}
|
|
|
|
|
2014-08-06 09:19:32 +04:00
|
|
|
/* static */ nsRect
|
2010-03-15 01:56:26 +03:00
|
|
|
nsCaret::GetGeometryForFrame(nsIFrame* aFrame,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aFrameOffset,
|
2010-03-15 01:56:26 +03:00
|
|
|
nscoord* aBidiIndicatorSize)
|
2010-01-12 00:45:16 +03:00
|
|
|
{
|
|
|
|
nsPoint framePos(0, 0);
|
2014-08-06 09:19:32 +04:00
|
|
|
nsRect rect;
|
2010-11-25 04:35:01 +03:00
|
|
|
nsresult rv = aFrame->GetPointFromOffset(aFrameOffset, &framePos);
|
2014-08-06 09:19:32 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (aBidiIndicatorSize) {
|
|
|
|
*aBidiIndicatorSize = 0;
|
|
|
|
}
|
|
|
|
return rect;
|
|
|
|
}
|
2010-11-25 04:35:01 +03:00
|
|
|
|
2014-05-25 02:20:39 +04:00
|
|
|
nsIFrame* frame = aFrame->GetContentInsertionFrame();
|
|
|
|
if (!frame) {
|
|
|
|
frame = aFrame;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(!(frame->GetStateBits() & NS_FRAME_IN_REFLOW),
|
|
|
|
"We should not be in the middle of reflow");
|
2010-11-22 11:13:37 +03:00
|
|
|
nscoord baseline = frame->GetCaretBaseline();
|
2010-08-31 22:54:44 +04:00
|
|
|
nscoord ascent = 0, descent = 0;
|
2016-03-17 08:55:48 +03:00
|
|
|
RefPtr<nsFontMetrics> fm =
|
|
|
|
nsLayoutUtils::GetInflatedFontMetricsForFrame(aFrame);
|
2010-08-31 22:54:44 +04:00
|
|
|
NS_ASSERTION(fm, "We should be able to get the font metrics");
|
|
|
|
if (fm) {
|
2011-04-08 08:18:43 +04:00
|
|
|
ascent = fm->MaxAscent();
|
|
|
|
descent = fm->MaxDescent();
|
2010-03-15 01:52:45 +03:00
|
|
|
}
|
2010-08-31 22:54:44 +04:00
|
|
|
nscoord height = ascent + descent;
|
2014-11-13 11:58:06 +03:00
|
|
|
WritingMode wm = aFrame->GetWritingMode();
|
|
|
|
bool vertical = wm.IsVertical();
|
2014-10-01 23:25:50 +04:00
|
|
|
if (vertical) {
|
2014-11-13 11:58:06 +03:00
|
|
|
if (wm.IsLineInverted()) {
|
|
|
|
framePos.x = baseline - descent;
|
|
|
|
} else {
|
|
|
|
framePos.x = baseline - ascent;
|
|
|
|
}
|
2014-10-01 23:25:50 +04:00
|
|
|
} else {
|
|
|
|
framePos.y = baseline - ascent;
|
|
|
|
}
|
2010-03-15 01:56:26 +03:00
|
|
|
Metrics caretMetrics = ComputeMetrics(aFrame, aFrameOffset, height);
|
2017-04-12 13:32:19 +03:00
|
|
|
|
|
|
|
nsTextFrame* textFrame = do_QueryFrame(aFrame);
|
|
|
|
if (textFrame) {
|
|
|
|
gfxTextRun* textRun =
|
|
|
|
textFrame->GetTextRun(nsTextFrame::TextRunType::eInflated);
|
|
|
|
if (textRun) {
|
|
|
|
// For "upstream" text where the textrun direction is reversed from the
|
|
|
|
// frame's inline-dir we want the caret to be painted before rather than
|
|
|
|
// after its nominal inline position, so we offset by its width.
|
|
|
|
bool textRunDirIsReverseOfFrame =
|
|
|
|
wm.IsInlineReversed() != textRun->IsInlineReversed();
|
|
|
|
// However, in sideways-lr mode we invert this behavior because this is
|
|
|
|
// the one writing mode where bidi-LTR corresponds to inline-reversed
|
|
|
|
// already, which reverses the desired caret placement behavior.
|
|
|
|
// Note that the following condition is equivalent to:
|
|
|
|
// if ( (!textRun->IsSidewaysLeft() && textRunDirIsReverseOfFrame) ||
|
|
|
|
// (textRun->IsSidewaysLeft() && !textRunDirIsReverseOfFrame) )
|
|
|
|
if (textRunDirIsReverseOfFrame != textRun->IsSidewaysLeft()) {
|
|
|
|
int dir = wm.IsBidiLTR() ? -1 : 1;
|
|
|
|
if (vertical) {
|
|
|
|
framePos.y += dir * caretMetrics.mCaretWidth;
|
|
|
|
} else {
|
|
|
|
framePos.x += dir * caretMetrics.mCaretWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-01 23:25:50 +04:00
|
|
|
rect = nsRect(framePos, vertical ? nsSize(height, caretMetrics.mCaretWidth) :
|
|
|
|
nsSize(caretMetrics.mCaretWidth, height));
|
2010-03-15 01:52:45 +03:00
|
|
|
|
2014-10-01 23:25:50 +04:00
|
|
|
// Clamp the inline-position to be within our scroll frame. If we don't, then
|
|
|
|
// it clips us, and we don't appear at all. See bug 335560.
|
2017-04-30 18:30:08 +03:00
|
|
|
nsIFrame* scrollFrame =
|
2017-05-01 20:32:52 +03:00
|
|
|
nsLayoutUtils::GetClosestFrameOfType(aFrame, LayoutFrameType::Scroll);
|
2010-03-15 01:52:45 +03:00
|
|
|
if (scrollFrame) {
|
2010-03-15 01:56:26 +03:00
|
|
|
// First, use the scrollFrame to get at the scrollable view that we're in.
|
2010-03-15 01:52:45 +03:00
|
|
|
nsIScrollableFrame *sf = do_QueryFrame(scrollFrame);
|
|
|
|
nsIFrame *scrolled = sf->GetScrolledFrame();
|
2014-08-06 09:19:32 +04:00
|
|
|
nsRect caretInScroll = rect + aFrame->GetOffsetTo(scrolled);
|
2010-03-15 01:52:45 +03:00
|
|
|
|
2014-10-01 23:25:50 +04:00
|
|
|
// Now see if the caret extends beyond the view's bounds. If it does,
|
2010-03-15 01:52:45 +03:00
|
|
|
// then snap it back, put it as close to the edge as it can.
|
2014-10-01 23:25:50 +04:00
|
|
|
if (vertical) {
|
|
|
|
nscoord overflow = caretInScroll.YMost() -
|
|
|
|
scrolled->GetVisualOverflowRectRelativeToSelf().height;
|
|
|
|
if (overflow > 0) {
|
|
|
|
rect.y -= overflow;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nscoord overflow = caretInScroll.XMost() -
|
|
|
|
scrolled->GetVisualOverflowRectRelativeToSelf().width;
|
|
|
|
if (overflow > 0) {
|
|
|
|
rect.x -= overflow;
|
|
|
|
}
|
2014-08-06 09:19:32 +04:00
|
|
|
}
|
2010-03-15 01:52:45 +03:00
|
|
|
}
|
|
|
|
|
2014-08-06 09:19:32 +04:00
|
|
|
if (aBidiIndicatorSize) {
|
2010-03-15 01:52:45 +03:00
|
|
|
*aBidiIndicatorSize = caretMetrics.mBidiIndicatorSize;
|
2014-08-06 09:19:32 +04:00
|
|
|
}
|
|
|
|
return rect;
|
2010-03-15 01:56:26 +03:00
|
|
|
}
|
|
|
|
|
2015-09-09 11:47:20 +03:00
|
|
|
nsIFrame*
|
|
|
|
nsCaret::GetFrameAndOffset(Selection* aSelection,
|
|
|
|
nsINode* aOverrideNode, int32_t aOverrideOffset,
|
|
|
|
int32_t* aFrameOffset)
|
2010-03-15 01:56:26 +03:00
|
|
|
{
|
2014-08-06 09:19:29 +04:00
|
|
|
nsINode* focusNode;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t focusOffset;
|
2014-08-06 09:19:29 +04:00
|
|
|
|
|
|
|
if (aOverrideNode) {
|
|
|
|
focusNode = aOverrideNode;
|
|
|
|
focusOffset = aOverrideOffset;
|
2014-08-06 09:19:31 +04:00
|
|
|
} else if (aSelection) {
|
2014-08-06 09:19:29 +04:00
|
|
|
focusNode = aSelection->GetFocusNode();
|
|
|
|
aSelection->GetFocusOffset(&focusOffset);
|
2014-08-06 09:19:31 +04:00
|
|
|
} else {
|
|
|
|
return nullptr;
|
2014-08-06 09:19:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!focusNode || !focusNode->IsContent()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2014-08-06 09:19:29 +04:00
|
|
|
}
|
2010-03-15 01:56:26 +03:00
|
|
|
|
2014-08-06 09:19:29 +04:00
|
|
|
nsIContent* contentNode = focusNode->AsContent();
|
|
|
|
nsFrameSelection* frameSelection = aSelection->GetFrameSelection();
|
2014-11-20 13:45:22 +03:00
|
|
|
nsBidiLevel bidiLevel = frameSelection->GetCaretBidiLevel();
|
2010-03-15 01:56:26 +03:00
|
|
|
nsIFrame* frame;
|
2014-08-06 09:19:29 +04:00
|
|
|
nsresult rv = nsCaret::GetCaretFrameForNodeOffset(
|
|
|
|
frameSelection, contentNode, focusOffset,
|
|
|
|
frameSelection->GetHint(), bidiLevel, &frame, aFrameOffset);
|
|
|
|
if (NS_FAILED(rv) || !frame) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2014-08-06 09:19:29 +04:00
|
|
|
}
|
2010-03-15 01:56:26 +03:00
|
|
|
|
2014-08-06 09:19:29 +04:00
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsIFrame*
|
|
|
|
nsCaret::GetGeometry(nsISelection* aSelection, nsRect* aRect)
|
|
|
|
{
|
|
|
|
int32_t frameOffset;
|
2016-06-17 16:32:49 +03:00
|
|
|
Selection* selection = aSelection ? aSelection->AsSelection() : nullptr;
|
|
|
|
nsIFrame* frame = GetFrameAndOffset(selection, nullptr, 0, &frameOffset);
|
2014-08-06 09:19:29 +04:00
|
|
|
if (frame) {
|
2014-08-06 09:19:32 +04:00
|
|
|
*aRect = GetGeometryForFrame(frame, frameOffset, nullptr);
|
2014-08-06 09:19:29 +04:00
|
|
|
}
|
2010-03-15 01:56:26 +03:00
|
|
|
return frame;
|
2010-01-12 00:45:16 +03:00
|
|
|
}
|
|
|
|
|
2014-08-06 09:19:27 +04:00
|
|
|
Selection*
|
|
|
|
nsCaret::GetSelectionInternal()
|
|
|
|
{
|
2016-06-17 16:32:49 +03:00
|
|
|
nsISelection* domSelection = GetSelection();
|
|
|
|
return domSelection ? domSelection->AsSelection() : nullptr;
|
2014-08-06 09:19:27 +04:00
|
|
|
}
|
|
|
|
|
2017-08-15 05:31:32 +03:00
|
|
|
void nsCaret::SchedulePaint(nsISelection* aSelection)
|
2014-08-06 09:19:27 +04:00
|
|
|
{
|
2017-08-15 05:31:32 +03:00
|
|
|
Selection* selection;
|
|
|
|
if (aSelection) {
|
|
|
|
selection = aSelection->AsSelection();
|
|
|
|
} else {
|
|
|
|
selection = GetSelectionInternal();
|
|
|
|
}
|
2014-08-06 09:19:31 +04:00
|
|
|
nsINode* focusNode;
|
|
|
|
if (mOverrideContent) {
|
|
|
|
focusNode = mOverrideContent;
|
|
|
|
} else if (selection) {
|
|
|
|
focusNode = selection->GetFocusNode();
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-06 09:19:27 +04:00
|
|
|
if (!focusNode || !focusNode->IsContent()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsIFrame* f = focusNode->AsContent()->GetPrimaryFrame();
|
|
|
|
if (!f) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// This may not be the correct continuation frame, but that's OK since we're
|
|
|
|
// just scheduling a paint of the window (or popup).
|
|
|
|
f->SchedulePaint();
|
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
void nsCaret::SetVisibilityDuringSelection(bool aVisibility)
|
2003-02-28 02:09:51 +03:00
|
|
|
{
|
|
|
|
mShowDuringSelection = aVisibility;
|
2014-08-06 09:19:29 +04:00
|
|
|
SchedulePaint();
|
2003-02-28 02:09:51 +03:00
|
|
|
}
|
|
|
|
|
2014-08-06 09:19:31 +04:00
|
|
|
void
|
|
|
|
nsCaret::SetCaretPosition(nsIDOMNode* aNode, int32_t aOffset)
|
2003-02-28 02:09:51 +03:00
|
|
|
{
|
2014-08-06 09:19:30 +04:00
|
|
|
mOverrideContent = do_QueryInterface(aNode);
|
|
|
|
mOverrideOffset = aOffset;
|
2014-08-06 09:19:29 +04:00
|
|
|
|
2014-08-06 09:19:31 +04:00
|
|
|
ResetBlinking();
|
2014-08-06 09:19:29 +04:00
|
|
|
SchedulePaint();
|
2006-04-18 03:16:46 +04:00
|
|
|
}
|
|
|
|
|
Bug 1048752. Part 22: Factor out SelectionLanguageChange call to run early in nsCaret::GetPaintGeometry. r=tn
This code is somewhat tricky. nsCaret::ComputeCaretRects was checking to see
if we have a bidi keyboard, and if so, what direction it's set to.
If the direction changed from the last direction seen for *this caret*,
we fired a SelectionLanguageChange notification on the caret's current
Selection. This looked bogus because the caret can be switched between
selections so it would seem some selections won't get a notification when
they should, but that's how it was. Also, when the SelectionLanguageChange
notification fired we then didn't draw the caret in that iteration, which
seems even more bogus.
This patch fixes all that by moving the logic to fire SelectionLanguageChange
out to GetPaintGeometry and firing the notification every single time without
trying to detect whether the state has changed or not. I carefully examined
the implementation of SelectionLanguageChange and I'm pretty sure it's
idempotent so this should be correct. That doesn't look like an
expensive function, and runs at most once per window paint, so I'm not
worried about perf. Because we now fire SelectionLanguageChange before
reading selection or frame state, it should be fine to carry on after
calling SelectionLanguageChange and drawing the caret based on whatever
changes SelectionLanguageChange has performed.
This also lets us remove mKeyboardRTL, which as noted above seems inherently
bogus.
--HG--
extra : rebase_source : 3ddfd10f6f30033e090e72b4bb43f2695218752e
2014-08-06 09:19:28 +04:00
|
|
|
void
|
|
|
|
nsCaret::CheckSelectionLanguageChange()
|
|
|
|
{
|
2014-08-12 17:27:02 +04:00
|
|
|
if (!IsBidiUI()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-10 15:42:23 +03:00
|
|
|
bool isKeyboardRTL = false;
|
|
|
|
nsIBidiKeyboard* bidiKeyboard = nsContentUtils::GetBidiKeyboard();
|
|
|
|
if (bidiKeyboard) {
|
|
|
|
bidiKeyboard->IsLangRTL(&isKeyboardRTL);
|
|
|
|
}
|
2014-08-12 17:27:02 +04:00
|
|
|
// Call SelectionLanguageChange on every paint. Mostly it will be a noop
|
|
|
|
// but it should be fast anyway. This guarantees we never paint the caret
|
|
|
|
// at the wrong place.
|
|
|
|
Selection* selection = GetSelectionInternal();
|
|
|
|
if (selection) {
|
|
|
|
selection->SelectionLanguageChange(isKeyboardRTL);
|
Bug 1048752. Part 22: Factor out SelectionLanguageChange call to run early in nsCaret::GetPaintGeometry. r=tn
This code is somewhat tricky. nsCaret::ComputeCaretRects was checking to see
if we have a bidi keyboard, and if so, what direction it's set to.
If the direction changed from the last direction seen for *this caret*,
we fired a SelectionLanguageChange notification on the caret's current
Selection. This looked bogus because the caret can be switched between
selections so it would seem some selections won't get a notification when
they should, but that's how it was. Also, when the SelectionLanguageChange
notification fired we then didn't draw the caret in that iteration, which
seems even more bogus.
This patch fixes all that by moving the logic to fire SelectionLanguageChange
out to GetPaintGeometry and firing the notification every single time without
trying to detect whether the state has changed or not. I carefully examined
the implementation of SelectionLanguageChange and I'm pretty sure it's
idempotent so this should be correct. That doesn't look like an
expensive function, and runs at most once per window paint, so I'm not
worried about perf. Because we now fire SelectionLanguageChange before
reading selection or frame state, it should be fine to carry on after
calling SelectionLanguageChange and drawing the caret based on whatever
changes SelectionLanguageChange has performed.
This also lets us remove mKeyboardRTL, which as noted above seems inherently
bogus.
--HG--
extra : rebase_source : 3ddfd10f6f30033e090e72b4bb43f2695218752e
2014-08-06 09:19:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-06 09:19:28 +04:00
|
|
|
nsIFrame*
|
|
|
|
nsCaret::GetPaintGeometry(nsRect* aRect)
|
2006-04-18 03:16:46 +04:00
|
|
|
{
|
2014-08-06 09:19:29 +04:00
|
|
|
// Return null if we should not be visible.
|
2014-08-06 09:19:31 +04:00
|
|
|
if (!IsVisible() || !mIsBlinkOn) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2014-08-06 09:19:29 +04:00
|
|
|
}
|
2006-04-18 03:16:46 +04:00
|
|
|
|
Bug 1048752. Part 22: Factor out SelectionLanguageChange call to run early in nsCaret::GetPaintGeometry. r=tn
This code is somewhat tricky. nsCaret::ComputeCaretRects was checking to see
if we have a bidi keyboard, and if so, what direction it's set to.
If the direction changed from the last direction seen for *this caret*,
we fired a SelectionLanguageChange notification on the caret's current
Selection. This looked bogus because the caret can be switched between
selections so it would seem some selections won't get a notification when
they should, but that's how it was. Also, when the SelectionLanguageChange
notification fired we then didn't draw the caret in that iteration, which
seems even more bogus.
This patch fixes all that by moving the logic to fire SelectionLanguageChange
out to GetPaintGeometry and firing the notification every single time without
trying to detect whether the state has changed or not. I carefully examined
the implementation of SelectionLanguageChange and I'm pretty sure it's
idempotent so this should be correct. That doesn't look like an
expensive function, and runs at most once per window paint, so I'm not
worried about perf. Because we now fire SelectionLanguageChange before
reading selection or frame state, it should be fine to carry on after
calling SelectionLanguageChange and drawing the caret based on whatever
changes SelectionLanguageChange has performed.
This also lets us remove mKeyboardRTL, which as noted above seems inherently
bogus.
--HG--
extra : rebase_source : 3ddfd10f6f30033e090e72b4bb43f2695218752e
2014-08-06 09:19:28 +04:00
|
|
|
// Update selection language direction now so the new direction will be
|
|
|
|
// taken into account when computing the caret position below.
|
|
|
|
CheckSelectionLanguageChange();
|
|
|
|
|
2014-08-06 09:19:29 +04:00
|
|
|
int32_t frameOffset;
|
|
|
|
nsIFrame *frame = GetFrameAndOffset(GetSelectionInternal(),
|
2014-08-06 09:19:30 +04:00
|
|
|
mOverrideContent, mOverrideOffset, &frameOffset);
|
2014-08-06 09:19:29 +04:00
|
|
|
if (!frame) {
|
2014-08-06 09:19:29 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now we have a frame, check whether it's appropriate to show the caret here
|
|
|
|
const nsStyleUserInterface* userinterface = frame->StyleUserInterface();
|
|
|
|
if ((!mIgnoreUserModify &&
|
2016-10-23 23:41:49 +03:00
|
|
|
userinterface->mUserModify == StyleUserModify::ReadOnly) ||
|
2016-10-23 01:08:18 +03:00
|
|
|
userinterface->mUserInput == StyleUserInput::None ||
|
|
|
|
userinterface->mUserInput == StyleUserInput::Disabled) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2014-08-06 09:19:29 +04:00
|
|
|
}
|
2006-04-18 03:16:46 +04:00
|
|
|
|
2014-08-06 09:19:28 +04:00
|
|
|
// If the offset falls outside of the frame, then don't paint the caret.
|
|
|
|
int32_t startOffset, endOffset;
|
2017-04-30 18:30:08 +03:00
|
|
|
if (frame->IsTextFrame() &&
|
2014-08-06 09:19:28 +04:00
|
|
|
(NS_FAILED(frame->GetOffsets(startOffset, endOffset)) ||
|
2017-04-30 18:30:08 +03:00
|
|
|
startOffset > frameOffset || endOffset < frameOffset)) {
|
2014-08-06 09:19:28 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect caretRect;
|
|
|
|
nsRect hookRect;
|
2014-08-06 09:19:29 +04:00
|
|
|
ComputeCaretRects(frame, frameOffset, &caretRect, &hookRect);
|
2014-08-06 09:19:28 +04:00
|
|
|
|
|
|
|
aRect->UnionRect(caretRect, hookRect);
|
2014-08-06 09:19:28 +04:00
|
|
|
return frame;
|
2014-08-06 09:19:28 +04:00
|
|
|
}
|
|
|
|
|
2017-02-15 00:49:27 +03:00
|
|
|
nsIFrame*
|
|
|
|
nsCaret::GetFrame(int32_t* aContentOffset) {
|
|
|
|
return GetFrameAndOffset(GetSelectionInternal(),
|
|
|
|
mOverrideContent,
|
|
|
|
mOverrideOffset,
|
|
|
|
aContentOffset);
|
|
|
|
}
|
|
|
|
|
2016-01-06 03:08:17 +03:00
|
|
|
void nsCaret::PaintCaret(DrawTarget& aDrawTarget,
|
2008-06-23 12:50:52 +04:00
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsPoint &aOffset)
|
2006-04-18 03:16:46 +04:00
|
|
|
{
|
2014-08-06 09:19:28 +04:00
|
|
|
int32_t contentOffset;
|
2017-02-15 00:49:27 +03:00
|
|
|
nsIFrame* frame = GetFrame(&contentOffset);
|
2014-08-06 09:19:29 +04:00
|
|
|
if (!frame) {
|
2014-08-06 09:19:28 +04:00
|
|
|
return;
|
|
|
|
}
|
2010-04-01 06:35:48 +04:00
|
|
|
NS_ASSERTION(frame == aForFrame, "We're referring different frame");
|
2014-08-06 09:19:28 +04:00
|
|
|
|
2014-10-19 16:22:22 +04:00
|
|
|
int32_t appUnitsPerDevPixel = frame->PresContext()->AppUnitsPerDevPixel();
|
2014-08-06 09:19:28 +04:00
|
|
|
|
|
|
|
nsRect caretRect;
|
|
|
|
nsRect hookRect;
|
|
|
|
ComputeCaretRects(frame, contentOffset, &caretRect, &hookRect);
|
2014-10-19 16:22:22 +04:00
|
|
|
|
|
|
|
Rect devPxCaretRect =
|
2014-10-29 20:07:11 +03:00
|
|
|
NSRectToSnappedRect(caretRect + aOffset, appUnitsPerDevPixel, aDrawTarget);
|
2014-10-19 16:22:22 +04:00
|
|
|
Rect devPxHookRect =
|
2014-10-29 20:07:11 +03:00
|
|
|
NSRectToSnappedRect(hookRect + aOffset, appUnitsPerDevPixel, aDrawTarget);
|
2014-10-19 16:22:22 +04:00
|
|
|
ColorPattern color(ToDeviceColor(frame->GetCaretColorAt(contentOffset)));
|
|
|
|
|
2014-10-29 20:07:11 +03:00
|
|
|
aDrawTarget.FillRect(devPxCaretRect, color);
|
2014-08-06 09:19:28 +04:00
|
|
|
if (!hookRect.IsEmpty()) {
|
2014-10-29 20:07:11 +03:00
|
|
|
aDrawTarget.FillRect(devPxHookRect, color);
|
2014-08-06 09:19:28 +04:00
|
|
|
}
|
2006-04-18 03:16:46 +04:00
|
|
|
}
|
1999-04-02 03:57:35 +04:00
|
|
|
|
2014-08-06 09:19:30 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCaret::NotifySelectionChanged(nsIDOMDocument *, nsISelection *aDomSel,
|
|
|
|
int16_t aReason)
|
1999-02-12 02:49:08 +03:00
|
|
|
{
|
2017-08-15 22:10:22 +03:00
|
|
|
// Note that aDomSel, per the comment below may not be the same as our
|
|
|
|
// selection, but that's OK since if that is the case, it wouldn't have
|
|
|
|
// mattered what IsVisible() returns here, so we just opt for checking
|
|
|
|
// the selection later down below.
|
|
|
|
if ((aReason & nsISelectionListener::MOUSEUP_REASON) || !IsVisible(aDomSel))//this wont do
|
2000-06-09 08:22:20 +04:00
|
|
|
return NS_OK;
|
2002-04-26 17:11:47 +04:00
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
nsCOMPtr<nsISelection> domSel(do_QueryReferent(mDomSelectionWeak));
|
2002-04-26 17:11:47 +04:00
|
|
|
|
|
|
|
// The same caret is shared amongst the document and any text widgets it
|
|
|
|
// may contain. This means that the caret could get notifications from
|
|
|
|
// multiple selections.
|
|
|
|
//
|
|
|
|
// If this notification is for a selection that is not the one the
|
|
|
|
// the caret is currently interested in (mDomSelectionWeak), then there
|
|
|
|
// is nothing to do!
|
|
|
|
|
|
|
|
if (domSel != aDomSel)
|
|
|
|
return NS_OK;
|
|
|
|
|
2014-08-06 09:19:30 +04:00
|
|
|
ResetBlinking();
|
2017-08-15 05:31:32 +03:00
|
|
|
SchedulePaint(aDomSel);
|
2002-04-26 17:11:47 +04:00
|
|
|
|
2000-09-07 09:26:25 +04:00
|
|
|
return NS_OK;
|
1999-02-12 02:49:08 +03:00
|
|
|
}
|
|
|
|
|
2014-08-06 09:19:30 +04:00
|
|
|
void nsCaret::ResetBlinking()
|
1999-03-02 07:26:49 +03:00
|
|
|
{
|
2014-08-06 09:19:31 +04:00
|
|
|
mIsBlinkOn = true;
|
|
|
|
|
2015-08-17 14:58:38 +03:00
|
|
|
if (mReadOnly || !mVisible || mHideCount) {
|
2014-08-06 09:19:30 +04:00
|
|
|
StopBlinking();
|
|
|
|
return;
|
2000-09-07 09:26:25 +04:00
|
|
|
}
|
|
|
|
|
2017-06-14 03:09:22 +03:00
|
|
|
uint32_t blinkRate = static_cast<uint32_t>(
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_CaretBlinkTime,
|
|
|
|
kDefaultCaretBlinkRate));
|
|
|
|
if (mBlinkRate == blinkRate) {
|
|
|
|
// If the rate hasn't changed, then there is nothing to do.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mBlinkRate = blinkRate;
|
|
|
|
|
2014-08-06 09:19:31 +04:00
|
|
|
if (mBlinkTimer) {
|
|
|
|
mBlinkTimer->Cancel();
|
|
|
|
} else {
|
2017-10-16 09:13:31 +03:00
|
|
|
nsIEventTarget* target = nullptr;
|
2017-08-03 06:03:05 +03:00
|
|
|
if (nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell)) {
|
|
|
|
if (nsCOMPtr<nsIDocument> doc = presShell->GetDocument()) {
|
2017-10-16 09:13:31 +03:00
|
|
|
target = doc->EventTargetFor(TaskCategory::Other);
|
2017-08-03 06:03:05 +03:00
|
|
|
}
|
|
|
|
}
|
2017-10-16 09:13:31 +03:00
|
|
|
|
|
|
|
mBlinkTimer = NS_NewTimer(target);
|
|
|
|
if (!mBlinkTimer) {
|
|
|
|
return;
|
|
|
|
}
|
2005-10-04 07:14:03 +04:00
|
|
|
}
|
2006-04-28 08:33:41 +04:00
|
|
|
|
2014-08-06 09:19:31 +04:00
|
|
|
if (blinkRate > 0) {
|
2015-04-29 17:23:19 +03:00
|
|
|
mBlinkCount = Preferences::GetInt("ui.caretBlinkCount", -1);
|
2017-02-14 02:45:23 +03:00
|
|
|
mBlinkTimer->InitWithNamedFuncCallback(CaretBlinkCallback, this, blinkRate,
|
|
|
|
nsITimer::TYPE_REPEATING_SLACK,
|
|
|
|
"nsCaret::CaretBlinkCallback_timer");
|
2014-08-06 09:19:31 +04:00
|
|
|
}
|
1999-02-12 02:49:08 +03:00
|
|
|
}
|
|
|
|
|
2008-07-16 14:52:01 +04:00
|
|
|
void nsCaret::StopBlinking()
|
1999-02-12 02:49:08 +03:00
|
|
|
{
|
2014-08-06 09:19:30 +04:00
|
|
|
if (mBlinkTimer)
|
|
|
|
{
|
|
|
|
mBlinkTimer->Cancel();
|
2017-06-17 05:20:27 +03:00
|
|
|
mBlinkRate = 0;
|
2014-08-06 09:19:30 +04:00
|
|
|
}
|
1999-02-12 02:49:08 +03:00
|
|
|
}
|
|
|
|
|
2014-11-20 13:45:22 +03:00
|
|
|
nsresult
|
2014-08-06 09:19:27 +04:00
|
|
|
nsCaret::GetCaretFrameForNodeOffset(nsFrameSelection* aFrameSelection,
|
|
|
|
nsIContent* aContentNode,
|
|
|
|
int32_t aOffset,
|
|
|
|
CaretAssociationHint aFrameHint,
|
2014-11-20 13:45:22 +03:00
|
|
|
nsBidiLevel aBidiLevel,
|
2014-08-06 09:19:27 +04:00
|
|
|
nsIFrame** aReturnFrame,
|
|
|
|
int32_t* aReturnOffset)
|
2005-11-16 12:37:01 +03:00
|
|
|
{
|
2014-08-06 09:19:24 +04:00
|
|
|
if (!aFrameSelection)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsIPresShell* presShell = aFrameSelection->GetShell();
|
2000-09-08 00:21:22 +04:00
|
|
|
if (!presShell)
|
2005-11-16 12:37:01 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2005-08-24 21:44:28 +04:00
|
|
|
|
2014-08-06 03:23:02 +04:00
|
|
|
if (!aContentNode || !aContentNode->IsInComposedDoc() ||
|
|
|
|
presShell->GetDocument() != aContentNode->GetComposedDoc())
|
2010-11-25 04:35:01 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIFrame* theFrame = nullptr;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t theFrameOffset = 0;
|
2000-09-08 00:21:22 +04:00
|
|
|
|
2014-08-06 09:19:24 +04:00
|
|
|
theFrame = aFrameSelection->GetFrameForNodeOffset(
|
|
|
|
aContentNode, aOffset, aFrameHint, &theFrameOffset);
|
2006-04-26 05:57:22 +04:00
|
|
|
if (!theFrame)
|
2005-11-16 12:37:01 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-09-08 00:21:22 +04:00
|
|
|
|
2007-11-08 07:07:00 +03:00
|
|
|
// if theFrame is after a text frame that's logically at the end of the line
|
|
|
|
// (e.g. if theFrame is a <br> frame), then put the caret at the end of
|
|
|
|
// that text frame instead. This way, the caret will be positioned as if
|
|
|
|
// trailing whitespace was not trimmed.
|
|
|
|
AdjustCaretFrameForLineEnd(&theFrame, &theFrameOffset);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2001-03-21 04:16:22 +03:00
|
|
|
// Mamdouh : modification of the caret to work at rtl and ltr with Bidi
|
|
|
|
//
|
2013-02-17 01:51:03 +04:00
|
|
|
// Direction Style from visibility->mDirection
|
2001-03-21 04:16:22 +03:00
|
|
|
// ------------------
|
|
|
|
// NS_STYLE_DIRECTION_LTR : LTR or Default
|
|
|
|
// NS_STYLE_DIRECTION_RTL
|
2015-05-28 15:05:25 +03:00
|
|
|
if (theFrame->PresContext()->BidiEnabled())
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
2005-11-16 12:37:01 +03:00
|
|
|
// If there has been a reflow, take the caret Bidi level to be the level of the current frame
|
2016-06-21 10:21:09 +03:00
|
|
|
if (aBidiLevel & BIDI_LEVEL_UNDEFINED) {
|
2016-10-06 11:49:14 +03:00
|
|
|
aBidiLevel = theFrame->GetEmbeddingLevel();
|
2016-06-21 10:21:09 +03:00
|
|
|
}
|
2001-03-21 04:16:22 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t start;
|
|
|
|
int32_t end;
|
2001-03-21 04:16:22 +03:00
|
|
|
nsIFrame* frameBefore;
|
|
|
|
nsIFrame* frameAfter;
|
2014-11-20 13:45:22 +03:00
|
|
|
nsBidiLevel levelBefore; // Bidi level of the character before the caret
|
|
|
|
nsBidiLevel levelAfter; // Bidi level of the character after the caret
|
2001-03-21 04:16:22 +03:00
|
|
|
|
|
|
|
theFrame->GetOffsets(start, end);
|
|
|
|
if (start == 0 || end == 0 || start == theFrameOffset || end == theFrameOffset)
|
|
|
|
{
|
2014-08-06 09:19:24 +04:00
|
|
|
nsPrevNextBidiLevels levels = aFrameSelection->
|
2011-10-17 18:59:28 +04:00
|
|
|
GetPrevNextBidiLevels(aContentNode, aOffset, false);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2005-11-16 12:37:01 +03:00
|
|
|
/* Boundary condition, we need to know the Bidi levels of the characters before and after the caret */
|
2006-04-26 05:57:22 +04:00
|
|
|
if (levels.mFrameBefore || levels.mFrameAfter)
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
2006-04-26 05:57:22 +04:00
|
|
|
frameBefore = levels.mFrameBefore;
|
|
|
|
frameAfter = levels.mFrameAfter;
|
|
|
|
levelBefore = levels.mLevelBefore;
|
|
|
|
levelAfter = levels.mLevelAfter;
|
|
|
|
|
2005-11-16 12:37:01 +03:00
|
|
|
if ((levelBefore != levelAfter) || (aBidiLevel != levelBefore))
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
2013-01-15 16:22:03 +04:00
|
|
|
aBidiLevel = std::max(aBidiLevel, std::min(levelBefore, levelAfter)); // rule c3
|
|
|
|
aBidiLevel = std::min(aBidiLevel, std::max(levelBefore, levelAfter)); // rule c4
|
2005-11-16 12:37:01 +03:00
|
|
|
if (aBidiLevel == levelBefore // rule c1
|
2014-11-20 13:45:22 +03:00
|
|
|
|| (aBidiLevel > levelBefore && aBidiLevel < levelAfter &&
|
|
|
|
IS_SAME_DIRECTION(aBidiLevel, levelBefore)) // rule c5
|
|
|
|
|| (aBidiLevel < levelBefore && aBidiLevel > levelAfter &&
|
|
|
|
IS_SAME_DIRECTION(aBidiLevel, levelBefore))) // rule c9
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
|
|
|
if (theFrame != frameBefore)
|
|
|
|
{
|
2005-11-16 12:37:01 +03:00
|
|
|
if (frameBefore) // if there is a frameBefore, move into it
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
|
|
|
theFrame = frameBefore;
|
|
|
|
theFrame->GetOffsets(start, end);
|
|
|
|
theFrameOffset = end;
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
else
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
|
|
|
// if there is no frameBefore, we must be at the beginning of the line
|
|
|
|
// so we stay with the current frame.
|
|
|
|
// Exception: when the first frame on the line has a different Bidi level from the paragraph level, there is no
|
2006-08-03 10:24:11 +04:00
|
|
|
// real frame for the caret to be in. We have to find the visually first frame on the line.
|
2016-10-06 11:49:14 +03:00
|
|
|
nsBidiLevel baseLevel = frameAfter->GetBaseLevel();
|
2001-03-21 04:16:22 +03:00
|
|
|
if (baseLevel != levelAfter)
|
|
|
|
{
|
2014-11-22 17:39:03 +03:00
|
|
|
nsPeekOffsetStruct pos(eSelectBeginLine, eDirPrevious, 0,
|
|
|
|
nsPoint(0, 0), false, true, false,
|
2015-01-15 19:24:49 +03:00
|
|
|
true, false);
|
2006-09-12 00:43:01 +04:00
|
|
|
if (NS_SUCCEEDED(frameAfter->PeekOffset(&pos))) {
|
2006-08-03 10:24:11 +04:00
|
|
|
theFrame = pos.mResultFrame;
|
|
|
|
theFrameOffset = pos.mContentOffset;
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-11-16 12:37:01 +03:00
|
|
|
else if (aBidiLevel == levelAfter // rule c2
|
2014-11-20 13:45:22 +03:00
|
|
|
|| (aBidiLevel > levelBefore && aBidiLevel < levelAfter &&
|
|
|
|
IS_SAME_DIRECTION(aBidiLevel, levelAfter)) // rule c6
|
|
|
|
|| (aBidiLevel < levelBefore && aBidiLevel > levelAfter &&
|
|
|
|
IS_SAME_DIRECTION(aBidiLevel, levelAfter))) // rule c10
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
|
|
|
if (theFrame != frameAfter)
|
|
|
|
{
|
|
|
|
if (frameAfter)
|
|
|
|
{
|
2005-11-16 12:37:01 +03:00
|
|
|
// if there is a frameAfter, move into it
|
2001-03-21 04:16:22 +03:00
|
|
|
theFrame = frameAfter;
|
|
|
|
theFrame->GetOffsets(start, end);
|
|
|
|
theFrameOffset = start;
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
else
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
|
|
|
// if there is no frameAfter, we must be at the end of the line
|
|
|
|
// so we stay with the current frame.
|
|
|
|
// Exception: when the last frame on the line has a different Bidi level from the paragraph level, there is no
|
2006-08-03 10:24:11 +04:00
|
|
|
// real frame for the caret to be in. We have to find the visually last frame on the line.
|
2016-10-06 11:49:14 +03:00
|
|
|
nsBidiLevel baseLevel = frameBefore->GetBaseLevel();
|
2001-03-21 04:16:22 +03:00
|
|
|
if (baseLevel != levelBefore)
|
|
|
|
{
|
2014-11-22 17:39:03 +03:00
|
|
|
nsPeekOffsetStruct pos(eSelectEndLine, eDirNext, 0,
|
|
|
|
nsPoint(0, 0), false, true, false,
|
2015-01-15 19:24:49 +03:00
|
|
|
true, false);
|
2006-09-12 00:43:01 +04:00
|
|
|
if (NS_SUCCEEDED(frameBefore->PeekOffset(&pos))) {
|
2006-08-03 10:24:11 +04:00
|
|
|
theFrame = pos.mResultFrame;
|
|
|
|
theFrameOffset = pos.mContentOffset;
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-11-16 12:37:01 +03:00
|
|
|
else if (aBidiLevel > levelBefore && aBidiLevel < levelAfter // rule c7/8
|
2014-11-20 13:45:22 +03:00
|
|
|
&& IS_SAME_DIRECTION(levelBefore, levelAfter) // before and after have the same parity
|
|
|
|
&& !IS_SAME_DIRECTION(aBidiLevel, levelAfter)) // caret has different parity
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
2014-08-06 09:19:24 +04:00
|
|
|
if (NS_SUCCEEDED(aFrameSelection->GetFrameFromLevel(frameAfter, eDirNext, aBidiLevel, &theFrame)))
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
|
|
|
theFrame->GetOffsets(start, end);
|
2016-10-06 11:49:14 +03:00
|
|
|
levelAfter = theFrame->GetEmbeddingLevel();
|
2014-11-20 13:45:22 +03:00
|
|
|
if (IS_LEVEL_RTL(aBidiLevel)) // c8: caret to the right of the rightmost character
|
|
|
|
theFrameOffset = IS_LEVEL_RTL(levelAfter) ? start : end;
|
2001-03-21 04:16:22 +03:00
|
|
|
else // c7: caret to the left of the leftmost character
|
2014-11-20 13:45:22 +03:00
|
|
|
theFrameOffset = IS_LEVEL_RTL(levelAfter) ? end : start;
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
}
|
2005-11-16 12:37:01 +03:00
|
|
|
else if (aBidiLevel < levelBefore && aBidiLevel > levelAfter // rule c11/12
|
2014-11-20 13:45:22 +03:00
|
|
|
&& IS_SAME_DIRECTION(levelBefore, levelAfter) // before and after have the same parity
|
|
|
|
&& !IS_SAME_DIRECTION(aBidiLevel, levelAfter)) // caret has different parity
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
2014-08-06 09:19:24 +04:00
|
|
|
if (NS_SUCCEEDED(aFrameSelection->GetFrameFromLevel(frameBefore, eDirPrevious, aBidiLevel, &theFrame)))
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
|
|
|
theFrame->GetOffsets(start, end);
|
2016-10-06 11:49:14 +03:00
|
|
|
levelBefore = theFrame->GetEmbeddingLevel();
|
2014-11-20 13:45:22 +03:00
|
|
|
if (IS_LEVEL_RTL(aBidiLevel)) // c12: caret to the left of the leftmost character
|
|
|
|
theFrameOffset = IS_LEVEL_RTL(levelBefore) ? end : start;
|
2001-03-21 04:16:22 +03:00
|
|
|
else // c11: caret to the right of the rightmost character
|
2014-11-20 13:45:22 +03:00
|
|
|
theFrameOffset = IS_LEVEL_RTL(levelBefore) ? start : end;
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
2014-11-20 13:45:22 +03:00
|
|
|
}
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-25 04:35:01 +03:00
|
|
|
|
2005-11-16 12:37:01 +03:00
|
|
|
*aReturnFrame = theFrame;
|
|
|
|
*aReturnOffset = theFrameOffset;
|
|
|
|
return NS_OK;
|
1999-02-12 02:49:08 +03:00
|
|
|
}
|
|
|
|
|
2014-06-23 02:02:59 +04:00
|
|
|
size_t nsCaret::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t total = aMallocSizeOf(this);
|
|
|
|
if (mPresShell) {
|
|
|
|
// We only want the size of the nsWeakReference object, not the PresShell
|
|
|
|
// (since we don't own the PresShell).
|
|
|
|
total += mPresShell->SizeOfOnlyThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
if (mDomSelectionWeak) {
|
|
|
|
// We only want size of the nsWeakReference object, not the selection
|
|
|
|
// (again, we don't own the selection).
|
|
|
|
total += mDomSelectionWeak->SizeOfOnlyThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
if (mBlinkTimer) {
|
|
|
|
total += mBlinkTimer->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsCaret::IsMenuPopupHidingCaret()
|
2008-04-01 12:35:11 +04:00
|
|
|
{
|
2008-09-08 16:23:38 +04:00
|
|
|
#ifdef MOZ_XUL
|
2008-04-01 12:35:11 +04:00
|
|
|
// Check if there are open popups.
|
|
|
|
nsXULPopupManager *popMgr = nsXULPopupManager::GetInstance();
|
2012-11-29 20:14:13 +04:00
|
|
|
nsTArray<nsIFrame*> popups;
|
|
|
|
popMgr->GetVisiblePopups(popups);
|
2008-04-01 12:35:11 +04:00
|
|
|
|
|
|
|
if (popups.Length() == 0)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false; // No popups, so caret can't be hidden by them.
|
2008-04-01 12:35:11 +04:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
// Get the selection focus content, that's where the caret would
|
2008-04-01 12:35:11 +04:00
|
|
|
// go if it was drawn.
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
nsCOMPtr<nsISelection> domSelection = do_QueryReferent(mDomSelectionWeak);
|
|
|
|
if (!domSelection)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true; // No selection/caret to draw.
|
2008-04-01 12:35:11 +04:00
|
|
|
domSelection->GetFocusNode(getter_AddRefs(node));
|
|
|
|
if (!node)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true; // No selection/caret to draw.
|
2008-04-01 12:35:11 +04:00
|
|
|
nsCOMPtr<nsIContent> caretContent = do_QueryInterface(node);
|
2008-04-09 10:16:09 +04:00
|
|
|
if (!caretContent)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true; // No selection/caret to draw.
|
2008-04-01 12:35:11 +04:00
|
|
|
|
|
|
|
// If there's a menu popup open before the popup with
|
|
|
|
// the caret, don't show the caret.
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i=0; i<popups.Length(); i++) {
|
2008-04-01 12:35:11 +04:00
|
|
|
nsMenuPopupFrame* popupFrame = static_cast<nsMenuPopupFrame*>(popups[i]);
|
|
|
|
nsIContent* popupContent = popupFrame->GetContent();
|
|
|
|
|
|
|
|
if (nsContentUtils::ContentIsDescendantOf(caretContent, popupContent)) {
|
|
|
|
// The caret is in this popup. There were no menu popups before this
|
|
|
|
// popup, so don't hide the caret.
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-04-01 12:35:11 +04:00
|
|
|
}
|
|
|
|
|
2008-04-30 20:54:16 +04:00
|
|
|
if (popupFrame->PopupType() == ePopupTypeMenu && !popupFrame->IsContextMenu()) {
|
2008-04-01 12:35:11 +04:00
|
|
|
// This is an open menu popup. It does not contain the caret (else we'd
|
|
|
|
// have returned above). Even if the caret is in a subsequent popup,
|
|
|
|
// or another document/frame, it should be hidden.
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-04-01 12:35:11 +04:00
|
|
|
}
|
|
|
|
}
|
2008-09-08 16:23:38 +04:00
|
|
|
#endif
|
2008-04-01 12:35:11 +04:00
|
|
|
|
|
|
|
// There are no open menu popups, no need to hide the caret.
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-04-01 12:35:11 +04:00
|
|
|
}
|
1999-09-15 03:41:19 +04:00
|
|
|
|
2014-08-06 09:19:28 +04:00
|
|
|
void
|
|
|
|
nsCaret::ComputeCaretRects(nsIFrame* aFrame, int32_t aFrameOffset,
|
|
|
|
nsRect* aCaretRect, nsRect* aHookRect)
|
2003-02-28 02:09:51 +03:00
|
|
|
{
|
2005-08-11 07:44:16 +04:00
|
|
|
NS_ASSERTION(aFrame, "Should have a frame here");
|
|
|
|
|
2015-09-24 12:23:34 +03:00
|
|
|
WritingMode wm = aFrame->GetWritingMode();
|
|
|
|
bool isVertical = wm.IsVertical();
|
2014-10-01 23:25:50 +04:00
|
|
|
|
2010-03-15 01:52:45 +03:00
|
|
|
nscoord bidiIndicatorSize;
|
2014-08-06 09:19:32 +04:00
|
|
|
*aCaretRect = GetGeometryForFrame(aFrame, aFrameOffset, &bidiIndicatorSize);
|
2007-08-14 00:51:16 +04:00
|
|
|
|
2006-11-01 21:31:42 +03:00
|
|
|
// on RTL frames the right edge of mCaretRect must be equal to framePos
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleVisibility* vis = aFrame->StyleVisibility();
|
2014-08-06 09:19:28 +04:00
|
|
|
if (NS_STYLE_DIRECTION_RTL == vis->mDirection) {
|
2014-10-01 23:25:50 +04:00
|
|
|
if (isVertical) {
|
|
|
|
aCaretRect->y -= aCaretRect->height;
|
|
|
|
} else {
|
|
|
|
aCaretRect->x -= aCaretRect->width;
|
|
|
|
}
|
2014-08-06 09:19:28 +04:00
|
|
|
}
|
2006-11-01 21:31:42 +03:00
|
|
|
|
2015-11-10 15:42:23 +03:00
|
|
|
// Simon -- make a hook to draw to the left or right of the caret to show keyboard language direction
|
2014-08-06 09:19:28 +04:00
|
|
|
aHookRect->SetEmpty();
|
2015-11-10 15:42:23 +03:00
|
|
|
if (!IsBidiUI()) {
|
2014-08-12 17:27:02 +04:00
|
|
|
return;
|
|
|
|
}
|
2000-09-07 09:26:25 +04:00
|
|
|
|
2015-11-10 15:42:23 +03:00
|
|
|
bool isCaretRTL;
|
|
|
|
nsIBidiKeyboard* bidiKeyboard = nsContentUtils::GetBidiKeyboard();
|
|
|
|
// if bidiKeyboard->IsLangRTL() fails, there is no way to tell the
|
|
|
|
// keyboard direction, or the user has no right-to-left keyboard
|
|
|
|
// installed, so we never draw the hook.
|
|
|
|
if (bidiKeyboard && NS_SUCCEEDED(bidiKeyboard->IsLangRTL(&isCaretRTL))) {
|
|
|
|
// If keyboard language is RTL, draw the hook on the left; if LTR, to the right
|
2006-04-18 03:16:46 +04:00
|
|
|
// The height of the hook rectangle is the same as the width of the caret
|
|
|
|
// rectangle.
|
2014-10-01 23:25:50 +04:00
|
|
|
if (isVertical) {
|
2015-09-24 12:23:34 +03:00
|
|
|
bool isSidewaysLR = wm.IsVerticalLR() && !wm.IsLineInverted();
|
|
|
|
if (isSidewaysLR) {
|
|
|
|
aHookRect->SetRect(aCaretRect->x + bidiIndicatorSize,
|
|
|
|
aCaretRect->y + (!isCaretRTL ? bidiIndicatorSize * -1 :
|
|
|
|
aCaretRect->height),
|
|
|
|
aCaretRect->height,
|
|
|
|
bidiIndicatorSize);
|
|
|
|
} else {
|
|
|
|
aHookRect->SetRect(aCaretRect->XMost() - bidiIndicatorSize,
|
|
|
|
aCaretRect->y + (isCaretRTL ? bidiIndicatorSize * -1 :
|
|
|
|
aCaretRect->height),
|
|
|
|
aCaretRect->height,
|
|
|
|
bidiIndicatorSize);
|
|
|
|
}
|
2014-10-01 23:25:50 +04:00
|
|
|
} else {
|
|
|
|
aHookRect->SetRect(aCaretRect->x + (isCaretRTL ? bidiIndicatorSize * -1 :
|
|
|
|
aCaretRect->width),
|
|
|
|
aCaretRect->y + bidiIndicatorSize,
|
|
|
|
bidiIndicatorSize,
|
|
|
|
aCaretRect->width);
|
|
|
|
}
|
2000-09-07 09:26:25 +04:00
|
|
|
}
|
2006-04-18 03:16:46 +04:00
|
|
|
}
|
2005-08-22 04:25:20 +04:00
|
|
|
|
1999-02-12 02:49:08 +03:00
|
|
|
/* static */
|
2014-08-06 09:19:29 +04:00
|
|
|
void nsCaret::CaretBlinkCallback(nsITimer* aTimer, void* aClosure)
|
1999-02-12 02:49:08 +03:00
|
|
|
{
|
2014-08-06 09:19:29 +04:00
|
|
|
nsCaret* theCaret = reinterpret_cast<nsCaret*>(aClosure);
|
|
|
|
if (!theCaret) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-06 09:19:29 +04:00
|
|
|
theCaret->mIsBlinkOn = !theCaret->mIsBlinkOn;
|
2014-08-06 09:19:29 +04:00
|
|
|
theCaret->SchedulePaint();
|
2015-04-29 17:23:19 +03:00
|
|
|
|
|
|
|
// mBlinkCount of -1 means blink count is not enabled.
|
|
|
|
if (theCaret->mBlinkCount == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Track the blink count, but only at end of a blink cycle.
|
|
|
|
if (!theCaret->mIsBlinkOn) {
|
|
|
|
// If we exceeded the blink count, stop the timer.
|
|
|
|
if (--theCaret->mBlinkCount <= 0) {
|
|
|
|
theCaret->StopBlinking();
|
|
|
|
}
|
|
|
|
}
|
1999-02-12 02:49:08 +03:00
|
|
|
}
|
|
|
|
|
2007-08-10 17:19:13 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsCaret::SetIgnoreUserModify(bool aIgnoreUserModify)
|
2007-08-10 17:19:13 +04:00
|
|
|
{
|
|
|
|
mIgnoreUserModify = aIgnoreUserModify;
|
2014-08-06 09:19:29 +04:00
|
|
|
SchedulePaint();
|
2007-08-10 17:19:13 +04:00
|
|
|
}
|