2013-11-18 19:24:16 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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/. */
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2011-08-09 19:14:36 +04:00
|
|
|
#include "nsTextBoxFrame.h"
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2014-10-26 03:15:26 +03:00
|
|
|
#include "gfx2DGlue.h"
|
2014-10-19 14:55:36 +04:00
|
|
|
#include "gfxUtils.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
2014-10-24 19:28:14 +04:00
|
|
|
#include "nsFontMetrics.h"
|
2002-04-09 06:29:21 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2000-02-17 02:00:52 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2011-04-08 05:04:40 +04:00
|
|
|
#include "nsRenderingContext.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
2000-02-17 02:00:52 +03:00
|
|
|
#include "nsIContent.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2000-03-31 11:02:06 +04:00
|
|
|
#include "nsBoxLayoutState.h"
|
2000-08-25 03:39:39 +04:00
|
|
|
#include "nsMenuBarListener.h"
|
2001-04-17 05:58:00 +04:00
|
|
|
#include "nsXPIDLString.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2002-02-21 16:39:39 +03:00
|
|
|
#include "nsIDOMElement.h"
|
2004-09-20 15:29:07 +04:00
|
|
|
#include "nsIDOMXULLabelElement.h"
|
2014-04-01 08:09:23 +04:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2001-12-18 01:51:39 +03:00
|
|
|
#include "nsITheme.h"
|
2001-12-17 10:14:49 +03:00
|
|
|
#include "nsUnicharUtils.h"
|
2004-04-30 03:34:19 +04:00
|
|
|
#include "nsContentUtils.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2007-08-06 12:15:00 +04:00
|
|
|
#include "nsCSSRendering.h"
|
2007-08-10 11:06:13 +04:00
|
|
|
#include "nsIReflowCallback.h"
|
2010-06-09 09:28:14 +04:00
|
|
|
#include "nsBoxFrame.h"
|
2011-05-27 08:53:03 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-08-09 19:14:36 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2012-07-11 08:03:55 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2013-03-01 08:06:16 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#endif
|
|
|
|
|
2002-02-19 23:41:32 +03:00
|
|
|
#include "nsBidiUtils.h"
|
2001-05-15 15:58:40 +04:00
|
|
|
#include "nsBidiPresUtils.h"
|
|
|
|
|
2011-05-27 08:53:03 +04:00
|
|
|
using namespace mozilla;
|
2014-10-19 14:55:36 +04:00
|
|
|
using namespace mozilla::gfx;
|
2011-05-27 08:53:03 +04:00
|
|
|
|
2000-02-17 02:00:52 +03:00
|
|
|
class nsAccessKeyInfo
|
|
|
|
{
|
|
|
|
public:
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mAccesskeyIndex;
|
2000-10-08 09:56:55 +04:00
|
|
|
nscoord mBeforeWidth, mAccessWidth, mAccessUnderlineSize, mAccessOffset;
|
2000-02-17 02:00:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsTextBoxFrame::gAlwaysAppendAccessKey = false;
|
|
|
|
bool nsTextBoxFrame::gAccessKeyPrefInitialized = false;
|
|
|
|
bool nsTextBoxFrame::gInsertSeparatorBeforeAccessKey = false;
|
|
|
|
bool nsTextBoxFrame::gInsertSeparatorPrefInitialized = false;
|
2001-04-17 05:58:00 +04:00
|
|
|
|
2005-10-27 01:46:39 +04:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewTextBoxFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2000-02-17 02:00:52 +03:00
|
|
|
{
|
2015-01-06 12:27:56 +03:00
|
|
|
return new (aPresShell) nsTextBoxFrame(aContext);
|
2009-09-12 20:49:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsTextBoxFrame)
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2013-03-01 08:06:16 +04:00
|
|
|
NS_QUERYFRAME_HEAD(nsTextBoxFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsTextBoxFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsTextBoxFrameSuper)
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsTextBoxFrame::AttributeChanged(int32_t aNameSpaceID,
|
2000-10-08 09:56:55 +04:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType)
|
2000-02-17 02:00:52 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aResize;
|
|
|
|
bool aRedraw;
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2006-04-10 04:16:29 +04:00
|
|
|
UpdateAttributes(aAttribute, aResize, aRedraw);
|
2000-10-08 09:56:55 +04:00
|
|
|
|
|
|
|
if (aResize) {
|
2007-03-31 01:11:41 +04:00
|
|
|
PresContext()->PresShell()->
|
2007-05-06 23:16:51 +04:00
|
|
|
FrameNeedsReflow(this, nsIPresShell::eStyleChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
2000-10-08 09:56:55 +04:00
|
|
|
} else if (aRedraw) {
|
2007-03-31 01:11:41 +04:00
|
|
|
nsBoxLayoutState state(PresContext());
|
2000-10-08 09:56:55 +04:00
|
|
|
Redraw(state);
|
|
|
|
}
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2002-02-21 16:39:39 +03:00
|
|
|
// If the accesskey changed, register for the new value
|
|
|
|
// The old value has been unregistered in nsXULElement::SetAttr
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::accesskey || aAttribute == nsGkAtoms::control)
|
2011-10-17 18:59:28 +04:00
|
|
|
RegUnregAccessKey(true);
|
2002-02-21 16:39:39 +03:00
|
|
|
|
2000-10-08 09:56:55 +04:00
|
|
|
return NS_OK;
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
|
|
|
|
2015-01-06 12:27:56 +03:00
|
|
|
nsTextBoxFrame::nsTextBoxFrame(nsStyleContext* aContext):
|
|
|
|
nsLeafBoxFrame(aContext), mAccessKeyInfo(nullptr), mCropType(CropRight),
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsReflowCallback(false)
|
2000-02-17 02:00:52 +03:00
|
|
|
{
|
2014-07-24 21:03:26 +04:00
|
|
|
MarkIntrinsicISizesDirty();
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
nsTextBoxFrame::~nsTextBoxFrame()
|
2000-02-17 02:00:52 +03:00
|
|
|
{
|
2003-12-21 07:04:05 +03:00
|
|
|
delete mAccessKeyInfo;
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
void
|
2014-05-25 02:20:40 +04:00
|
|
|
nsTextBoxFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2000-02-17 02:00:52 +03:00
|
|
|
{
|
2006-04-10 04:16:29 +04:00
|
|
|
nsTextBoxFrameSuper::Init(aContent, aParent, aPrevInFlow);
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aResize;
|
|
|
|
bool aRedraw;
|
2012-07-30 18:20:58 +04:00
|
|
|
UpdateAttributes(nullptr, aResize, aRedraw); /* update all */
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2002-02-21 16:39:39 +03:00
|
|
|
// register access key
|
2011-10-17 18:59:28 +04:00
|
|
|
RegUnregAccessKey(true);
|
2002-02-21 16:39:39 +03:00
|
|
|
}
|
|
|
|
|
2006-04-10 04:16:29 +04:00
|
|
|
void
|
2009-12-24 08:21:15 +03:00
|
|
|
nsTextBoxFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2002-02-21 16:39:39 +03:00
|
|
|
{
|
|
|
|
// unregister access key
|
2011-10-17 18:59:28 +04:00
|
|
|
RegUnregAccessKey(false);
|
2009-12-24 08:21:15 +03:00
|
|
|
nsTextBoxFrameSuper::DestroyFrom(aDestructRoot);
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2001-10-20 00:56:29 +04:00
|
|
|
nsTextBoxFrame::AlwaysAppendAccessKey()
|
|
|
|
{
|
|
|
|
if (!gAccessKeyPrefInitialized)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
gAccessKeyPrefInitialized = true;
|
2003-01-10 09:57:26 +03:00
|
|
|
|
2005-06-28 21:21:21 +04:00
|
|
|
const char* prefName = "intl.menuitems.alwaysappendaccesskeys";
|
2011-05-27 08:53:03 +04:00
|
|
|
nsAdoptingString val = Preferences::GetLocalizedString(prefName);
|
2014-05-22 07:48:51 +04:00
|
|
|
gAlwaysAppendAccessKey = val.EqualsLiteral("true");
|
2001-10-20 00:56:29 +04:00
|
|
|
}
|
|
|
|
return gAlwaysAppendAccessKey;
|
|
|
|
}
|
2005-07-20 12:40:13 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2005-07-20 12:40:13 +04:00
|
|
|
nsTextBoxFrame::InsertSeparatorBeforeAccessKey()
|
|
|
|
{
|
|
|
|
if (!gInsertSeparatorPrefInitialized)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
gInsertSeparatorPrefInitialized = true;
|
2005-07-20 12:40:13 +04:00
|
|
|
|
|
|
|
const char* prefName = "intl.menuitems.insertseparatorbeforeaccesskeys";
|
2011-05-27 08:53:03 +04:00
|
|
|
nsAdoptingString val = Preferences::GetLocalizedString(prefName);
|
2005-07-20 12:40:13 +04:00
|
|
|
gInsertSeparatorBeforeAccessKey = val.EqualsLiteral("true");
|
|
|
|
}
|
|
|
|
return gInsertSeparatorBeforeAccessKey;
|
|
|
|
}
|
2001-10-20 00:56:29 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsAsyncAccesskeyUpdate final : public nsIReflowCallback
|
2007-08-10 11:06:13 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit nsAsyncAccesskeyUpdate(nsIFrame* aFrame) : mWeakFrame(aFrame)
|
2007-08-10 11:06:13 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool ReflowFinished() override
|
2007-08-10 11:06:13 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool shouldFlush = false;
|
2007-08-10 11:06:13 +04:00
|
|
|
nsTextBoxFrame* frame =
|
|
|
|
static_cast<nsTextBoxFrame*>(mWeakFrame.GetFrame());
|
|
|
|
if (frame) {
|
|
|
|
shouldFlush = frame->UpdateAccesskey(mWeakFrame);
|
|
|
|
}
|
|
|
|
delete this;
|
|
|
|
return shouldFlush;
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ReflowCallbackCanceled() override
|
2007-12-01 10:22:44 +03:00
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2007-08-10 11:06:13 +04:00
|
|
|
nsWeakFrame mWeakFrame;
|
|
|
|
};
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2007-08-10 11:06:13 +04:00
|
|
|
nsTextBoxFrame::UpdateAccesskey(nsWeakFrame& aWeakThis)
|
|
|
|
{
|
|
|
|
nsAutoString accesskey;
|
|
|
|
nsCOMPtr<nsIDOMXULLabelElement> labelElement = do_QueryInterface(mContent);
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(aWeakThis.IsAlive(), false);
|
2007-08-10 11:06:13 +04:00
|
|
|
if (labelElement) {
|
|
|
|
// Accesskey may be stored on control.
|
2014-08-07 22:46:36 +04:00
|
|
|
labelElement->GetAccessKey(accesskey);
|
|
|
|
NS_ENSURE_TRUE(aWeakThis.IsAlive(), false);
|
2007-08-10 11:06:13 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accesskey);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!accesskey.Equals(mAccessKey)) {
|
|
|
|
// Need to get clean mTitle.
|
2014-05-24 01:32:37 +04:00
|
|
|
RecomputeTitle();
|
2007-08-10 11:06:13 +04:00
|
|
|
mAccessKey = accesskey;
|
|
|
|
UpdateAccessTitle();
|
|
|
|
PresContext()->PresShell()->
|
|
|
|
FrameNeedsReflow(this, nsIPresShell::eStyleChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-08-10 11:06:13 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-08-10 11:06:13 +04:00
|
|
|
}
|
|
|
|
|
2000-02-17 02:00:52 +03:00
|
|
|
void
|
2006-04-10 04:16:29 +04:00
|
|
|
nsTextBoxFrame::UpdateAttributes(nsIAtom* aAttribute,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aResize,
|
|
|
|
bool& aRedraw)
|
2000-02-17 02:00:52 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool doUpdateTitle = false;
|
2011-10-17 18:59:28 +04:00
|
|
|
aResize = false;
|
|
|
|
aRedraw = false;
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (aAttribute == nullptr || aAttribute == nsGkAtoms::crop) {
|
2006-04-24 09:40:11 +04:00
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2006-12-26 20:47:52 +03:00
|
|
|
{&nsGkAtoms::left, &nsGkAtoms::start, &nsGkAtoms::center,
|
2012-07-30 18:20:58 +04:00
|
|
|
&nsGkAtoms::right, &nsGkAtoms::end, nullptr};
|
2000-02-17 02:00:52 +03:00
|
|
|
CroppingStyle cropType;
|
2006-12-26 20:47:52 +03:00
|
|
|
switch (mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::crop,
|
2006-04-24 09:40:11 +04:00
|
|
|
strings, eCaseMatters)) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
2000-02-17 02:00:52 +03:00
|
|
|
cropType = CropLeft;
|
2006-04-24 09:40:11 +04:00
|
|
|
break;
|
|
|
|
case 2:
|
2000-02-17 02:00:52 +03:00
|
|
|
cropType = CropCenter;
|
2006-04-24 09:40:11 +04:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 4:
|
2000-02-17 02:00:52 +03:00
|
|
|
cropType = CropRight;
|
2006-04-24 09:40:11 +04:00
|
|
|
break;
|
|
|
|
default:
|
2000-02-17 02:00:52 +03:00
|
|
|
cropType = CropNone;
|
2006-04-24 09:40:11 +04:00
|
|
|
break;
|
|
|
|
}
|
2000-02-17 02:00:52 +03:00
|
|
|
|
|
|
|
if (cropType != mCropType) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aResize = true;
|
2000-02-17 02:00:52 +03:00
|
|
|
mCropType = cropType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (aAttribute == nullptr || aAttribute == nsGkAtoms::value) {
|
2014-05-24 01:32:37 +04:00
|
|
|
RecomputeTitle();
|
2011-10-17 18:59:28 +04:00
|
|
|
doUpdateTitle = true;
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (aAttribute == nullptr || aAttribute == nsGkAtoms::accesskey) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsReflowCallback = true;
|
2007-08-10 11:06:13 +04:00
|
|
|
// Ensure that layout is refreshed and reflow callback called.
|
2011-10-17 18:59:28 +04:00
|
|
|
aResize = true;
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
|
|
|
|
2000-10-08 09:56:55 +04:00
|
|
|
if (doUpdateTitle) {
|
|
|
|
UpdateAccessTitle();
|
2011-10-17 18:59:28 +04:00
|
|
|
aResize = true;
|
2000-10-08 09:56:55 +04:00
|
|
|
}
|
2002-02-21 16:39:39 +03:00
|
|
|
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
class nsDisplayXULTextBox : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayXULTextBox(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsTextBoxFrame* aFrame) :
|
2011-01-03 04:48:09 +03:00
|
|
|
nsDisplayItem(aBuilder, aFrame),
|
2011-10-17 18:59:28 +04:00
|
|
|
mDisableSubpixelAA(false)
|
2011-01-03 04:48:09 +03:00
|
|
|
{
|
2010-08-13 14:01:13 +04:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayXULTextBox);
|
2006-01-29 21:48:58 +03:00
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayXULTextBox() {
|
2010-08-13 14:01:13 +04:00
|
|
|
MOZ_COUNT_DTOR(nsDisplayXULTextBox);
|
2006-01-29 21:48:58 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-07 04:35:14 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsRenderingContext* aCtx) override;
|
2014-02-24 18:41:56 +04:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool* aSnap) override;
|
2010-07-16 01:07:49 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("XULTextBox", TYPE_XUL_TEXT_BOX)
|
2010-10-11 04:58:20 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsRect GetComponentAlphaBounds(nsDisplayListBuilder* aBuilder) override;
|
2011-01-03 04:48:09 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void DisableComponentAlpha() override {
|
2014-02-24 18:41:56 +04:00
|
|
|
mDisableSubpixelAA = true;
|
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
|
2011-07-04 08:59:19 +04:00
|
|
|
void PaintTextToContext(nsRenderingContext* aCtx,
|
|
|
|
nsPoint aOffset,
|
|
|
|
const nscolor* aColor);
|
2011-07-01 10:43:11 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mDisableSubpixelAA;
|
2006-01-26 05:29:17 +03:00
|
|
|
};
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2011-07-01 10:43:11 +04:00
|
|
|
static void
|
|
|
|
PaintTextShadowCallback(nsRenderingContext* aCtx,
|
|
|
|
nsPoint aShadowOffset,
|
|
|
|
const nscolor& aShadowColor,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
reinterpret_cast<nsDisplayXULTextBox*>(aData)->
|
2011-07-04 08:59:19 +04:00
|
|
|
PaintTextToContext(aCtx, aShadowOffset, &aShadowColor);
|
2011-07-01 10:43:11 +04:00
|
|
|
}
|
|
|
|
|
2008-11-26 01:59:06 +03:00
|
|
|
void
|
|
|
|
nsDisplayXULTextBox::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
2015-12-03 02:32:16 +03:00
|
|
|
DrawTargetAutoDisableSubpixelAntialiasing disable(aCtx->GetDrawTarget(),
|
2011-01-03 04:48:09 +03:00
|
|
|
mDisableSubpixelAA);
|
2011-07-01 10:43:11 +04:00
|
|
|
|
|
|
|
// Paint the text shadow before doing any foreground stuff
|
2011-07-04 08:59:19 +04:00
|
|
|
nsRect drawRect = static_cast<nsTextBoxFrame*>(mFrame)->mTextDrawRect +
|
|
|
|
ToReferenceFrame();
|
2011-07-01 10:43:11 +04:00
|
|
|
nsLayoutUtils::PaintTextShadow(mFrame, aCtx,
|
|
|
|
drawRect, mVisibleRect,
|
2013-02-17 01:51:02 +04:00
|
|
|
mFrame->StyleColor()->mColor,
|
2011-07-01 10:43:11 +04:00
|
|
|
PaintTextShadowCallback,
|
|
|
|
(void*)this);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
PaintTextToContext(aCtx, nsPoint(0, 0), nullptr);
|
2011-07-01 10:43:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-07-04 08:59:19 +04:00
|
|
|
nsDisplayXULTextBox::PaintTextToContext(nsRenderingContext* aCtx,
|
|
|
|
nsPoint aOffset,
|
|
|
|
const nscolor* aColor)
|
2011-07-01 10:43:11 +04:00
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsTextBoxFrame*>(mFrame)->
|
2011-07-01 12:21:46 +04:00
|
|
|
PaintTitle(*aCtx, mVisibleRect, ToReferenceFrame() + aOffset, aColor);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2008-11-26 01:59:06 +03:00
|
|
|
nsRect
|
2012-04-10 15:24:18 +04:00
|
|
|
nsDisplayXULTextBox::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) {
|
|
|
|
*aSnap = false;
|
2011-10-21 21:45:32 +04:00
|
|
|
return mFrame->GetVisualOverflowRectRelativeToSelf() + ToReferenceFrame();
|
2008-11-26 01:59:06 +03:00
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRect
|
|
|
|
nsDisplayXULTextBox::GetComponentAlphaBounds(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
return static_cast<nsTextBoxFrame*>(mFrame)->GetComponentAlphaBounds() +
|
|
|
|
ToReferenceFrame();
|
|
|
|
}
|
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
void
|
2006-01-26 05:29:17 +03:00
|
|
|
nsTextBoxFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
if (!IsVisibleForPainting(aBuilder))
|
2013-02-14 15:12:27 +04:00
|
|
|
return;
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2013-02-14 15:08:08 +04:00
|
|
|
nsLeafBoxFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2013-02-14 15:08:08 +04:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
2013-02-14 15:12:27 +04:00
|
|
|
nsDisplayXULTextBox(aBuilder, this));
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
void
|
2011-04-08 05:04:40 +04:00
|
|
|
nsTextBoxFrame::PaintTitle(nsRenderingContext& aRenderingContext,
|
2000-10-08 09:56:55 +04:00
|
|
|
const nsRect& aDirtyRect,
|
2011-07-01 12:21:46 +04:00
|
|
|
nsPoint aPt,
|
|
|
|
const nscolor* aOverrideColor)
|
2000-02-17 02:00:52 +03:00
|
|
|
{
|
2003-05-24 01:34:47 +04:00
|
|
|
if (mTitle.IsEmpty())
|
2006-01-26 05:29:17 +03:00
|
|
|
return;
|
|
|
|
|
2011-09-16 23:23:29 +04:00
|
|
|
DrawText(aRenderingContext, aDirtyRect, mTextDrawRect + aPt, aOverrideColor);
|
2008-10-01 04:57:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-08 05:04:40 +04:00
|
|
|
nsTextBoxFrame::DrawText(nsRenderingContext& aRenderingContext,
|
2011-09-16 23:23:29 +04:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aTextRect,
|
|
|
|
const nscolor* aOverrideColor)
|
2008-10-01 04:57:51 +04:00
|
|
|
{
|
|
|
|
nsPresContext* presContext = PresContext();
|
2014-10-19 14:55:36 +04:00
|
|
|
int32_t appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
|
|
|
|
DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
|
2000-10-08 09:56:55 +04:00
|
|
|
|
|
|
|
// paint the title
|
2001-06-01 02:19:43 +04:00
|
|
|
nscolor overColor;
|
|
|
|
nscolor underColor;
|
|
|
|
nscolor strikeColor;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t overStyle;
|
|
|
|
uint8_t underStyle;
|
|
|
|
uint8_t strikeStyle;
|
2011-04-23 09:16:41 +04:00
|
|
|
|
|
|
|
// Begin with no decorations
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t decorations = NS_STYLE_TEXT_DECORATION_LINE_NONE;
|
2011-04-23 09:16:41 +04:00
|
|
|
// A mask of all possible decorations.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t decorMask = NS_STYLE_TEXT_DECORATION_LINE_LINES_MASK;
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2015-03-03 19:38:31 +03:00
|
|
|
WritingMode wm = GetWritingMode();
|
|
|
|
bool vertical = wm.IsVertical();
|
2014-10-08 13:32:55 +04:00
|
|
|
|
2011-08-09 19:14:36 +04:00
|
|
|
nsIFrame* f = this;
|
2001-06-01 02:19:43 +04:00
|
|
|
do { // find decoration colors
|
2013-02-16 09:38:33 +04:00
|
|
|
nsStyleContext* context = f->StyleContext();
|
2011-08-09 19:14:36 +04:00
|
|
|
if (!context->HasTextDecorationLines()) {
|
|
|
|
break;
|
|
|
|
}
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleTextReset* styleText = context->StyleTextReset();
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2011-04-23 09:16:41 +04:00
|
|
|
if (decorMask & styleText->mTextDecorationLine) { // a decoration defined here
|
2011-03-31 16:27:03 +04:00
|
|
|
nscolor color;
|
|
|
|
if (aOverrideColor) {
|
|
|
|
color = *aOverrideColor;
|
|
|
|
} else {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isForeground;
|
2011-03-31 16:27:03 +04:00
|
|
|
styleText->GetDecorationColor(color, isForeground);
|
|
|
|
if (isForeground) {
|
2011-08-09 19:14:36 +04:00
|
|
|
color = nsLayoutUtils::GetColor(f, eCSSProperty_color);
|
2011-03-31 16:27:03 +04:00
|
|
|
}
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t style = styleText->GetDecorationStyle();
|
2011-03-31 16:27:03 +04:00
|
|
|
|
2011-04-23 09:16:41 +04:00
|
|
|
if (NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE & decorMask &
|
|
|
|
styleText->mTextDecorationLine) {
|
2003-05-15 07:42:21 +04:00
|
|
|
underColor = color;
|
2011-03-31 16:27:03 +04:00
|
|
|
underStyle = style;
|
2011-04-23 09:16:41 +04:00
|
|
|
decorMask &= ~NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE;
|
|
|
|
decorations |= NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE;
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2011-04-23 09:16:41 +04:00
|
|
|
if (NS_STYLE_TEXT_DECORATION_LINE_OVERLINE & decorMask &
|
|
|
|
styleText->mTextDecorationLine) {
|
2003-05-15 07:42:21 +04:00
|
|
|
overColor = color;
|
2011-03-31 16:27:03 +04:00
|
|
|
overStyle = style;
|
2011-04-23 09:16:41 +04:00
|
|
|
decorMask &= ~NS_STYLE_TEXT_DECORATION_LINE_OVERLINE;
|
|
|
|
decorations |= NS_STYLE_TEXT_DECORATION_LINE_OVERLINE;
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2011-04-23 09:16:41 +04:00
|
|
|
if (NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH & decorMask &
|
|
|
|
styleText->mTextDecorationLine) {
|
2003-05-15 07:42:21 +04:00
|
|
|
strikeColor = color;
|
2011-03-31 16:27:03 +04:00
|
|
|
strikeStyle = style;
|
2011-04-23 09:16:41 +04:00
|
|
|
decorMask &= ~NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH;
|
|
|
|
decorations |= NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH;
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
|
|
|
}
|
2011-08-09 19:14:36 +04:00
|
|
|
} while (0 != decorMask &&
|
2012-06-11 03:44:50 +04:00
|
|
|
(f = nsLayoutUtils::GetParentOrPlaceholderFor(f)));
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFontMetrics> fontMet;
|
2007-08-07 23:07:43 +04:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
|
2015-08-16 17:09:08 +03:00
|
|
|
fontMet->SetVertical(wm.IsVertical());
|
|
|
|
fontMet->SetTextOrientation(StyleVisibility()->mTextOrientation);
|
2007-08-07 23:07:43 +04:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
nscoord offset;
|
|
|
|
nscoord size;
|
2011-04-08 08:18:43 +04:00
|
|
|
nscoord ascent = fontMet->MaxAscent();
|
2007-08-06 12:15:00 +04:00
|
|
|
|
2015-03-03 19:38:31 +03:00
|
|
|
nsPoint baselinePt;
|
|
|
|
if (wm.IsVertical()) {
|
|
|
|
baselinePt.x =
|
|
|
|
presContext->RoundAppUnitsToNearestDevPixels(aTextRect.x +
|
|
|
|
(wm.IsVerticalRL() ? aTextRect.width - ascent : ascent));
|
|
|
|
baselinePt.y = aTextRect.y;
|
|
|
|
} else {
|
|
|
|
baselinePt.x = aTextRect.x;
|
|
|
|
baselinePt.y =
|
|
|
|
presContext->RoundAppUnitsToNearestDevPixels(aTextRect.y + ascent);
|
|
|
|
}
|
|
|
|
|
2015-11-09 07:19:00 +03:00
|
|
|
Point pt(presContext->AppUnitsToGfxUnits(aTextRect.x),
|
|
|
|
presContext->AppUnitsToGfxUnits(aTextRect.y));
|
|
|
|
Float width = presContext->AppUnitsToGfxUnits(aTextRect.width);
|
2007-09-03 19:27:26 +04:00
|
|
|
gfxFloat ascentPixel = presContext->AppUnitsToGfxUnits(ascent);
|
2014-10-26 03:15:26 +03:00
|
|
|
Float xInFrame = Float(PresContext()->AppUnitsToGfxUnits(mTextDrawRect.x));
|
2011-09-16 23:23:29 +04:00
|
|
|
gfxRect dirtyRect(presContext->AppUnitsToGfxUnits(aDirtyRect));
|
2008-10-01 09:46:18 +04:00
|
|
|
|
2015-03-03 19:38:31 +03:00
|
|
|
// XXX todo: vertical-mode support for decorations not tested yet,
|
|
|
|
// probably won't be positioned correctly
|
|
|
|
|
2008-10-01 09:46:18 +04:00
|
|
|
// Underlines are drawn before overlines, and both before the text
|
|
|
|
// itself, per http://www.w3.org/TR/CSS21/zindex.html point 7.2.1.4.1.1.
|
|
|
|
// (We don't apply this rule to the access-key underline because we only
|
|
|
|
// find out where that is as a side effect of drawing the text, in the
|
|
|
|
// general case -- see below.)
|
2015-12-01 01:02:26 +03:00
|
|
|
if (decorations & (NS_STYLE_TEXT_DECORATION_LINE_OVERLINE |
|
|
|
|
NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE)) {
|
2001-06-01 02:19:43 +04:00
|
|
|
fontMet->GetUnderline(offset, size);
|
2007-08-22 15:13:46 +04:00
|
|
|
gfxFloat offsetPixel = presContext->AppUnitsToGfxUnits(offset);
|
2015-11-09 07:19:00 +03:00
|
|
|
Float sizePixel = presContext->AppUnitsToGfxUnits(size);
|
2015-12-01 01:02:26 +03:00
|
|
|
if ((decorations & NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE) &&
|
2011-04-23 09:13:09 +04:00
|
|
|
underStyle != NS_STYLE_TEXT_DECORATION_STYLE_NONE) {
|
2014-10-26 03:15:26 +03:00
|
|
|
nsCSSRendering::PaintDecorationLine(this, *drawTarget,
|
|
|
|
ToRect(dirtyRect), underColor,
|
2015-11-09 07:19:00 +03:00
|
|
|
pt, xInFrame, Size(width, sizePixel),
|
2009-04-03 11:26:28 +04:00
|
|
|
ascentPixel, offsetPixel,
|
2014-10-08 13:32:55 +04:00
|
|
|
NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE, underStyle,
|
|
|
|
vertical);
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2015-12-01 01:02:26 +03:00
|
|
|
if ((decorations & NS_STYLE_TEXT_DECORATION_LINE_OVERLINE) &&
|
2011-04-23 09:13:09 +04:00
|
|
|
overStyle != NS_STYLE_TEXT_DECORATION_STYLE_NONE) {
|
2014-10-26 03:15:26 +03:00
|
|
|
nsCSSRendering::PaintDecorationLine(this, *drawTarget,
|
|
|
|
ToRect(dirtyRect), overColor,
|
2015-11-09 07:19:00 +03:00
|
|
|
pt, xInFrame, Size(width, sizePixel),
|
2009-04-03 11:26:28 +04:00
|
|
|
ascentPixel, ascentPixel,
|
2014-10-08 13:32:55 +04:00
|
|
|
NS_STYLE_TEXT_DECORATION_LINE_OVERLINE, overStyle,
|
|
|
|
vertical);
|
2008-10-01 09:46:18 +04:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2007-08-07 23:07:43 +04:00
|
|
|
|
2014-10-31 23:08:49 +03:00
|
|
|
nsRenderingContext refContext(
|
|
|
|
PresContext()->PresShell()->CreateReferenceRenderingContext());
|
2015-12-16 00:56:41 +03:00
|
|
|
DrawTarget* refDrawTarget = refContext.GetDrawTarget();
|
2011-01-16 23:23:33 +03:00
|
|
|
|
2015-12-16 00:56:41 +03:00
|
|
|
CalculateUnderline(refDrawTarget, *fontMet);
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2014-10-19 14:55:36 +04:00
|
|
|
nscolor c = aOverrideColor ? *aOverrideColor : StyleColor()->mColor;
|
|
|
|
ColorPattern color(ToDeviceColor(c));
|
2015-09-24 09:41:30 +03:00
|
|
|
aRenderingContext.ThebesContext()->SetColor(Color::FromABGR(c));
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2001-05-15 15:58:40 +04:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (mState & NS_FRAME_IS_BIDI) {
|
2008-06-16 13:28:17 +04:00
|
|
|
presContext->SetBidiEnabled();
|
2013-11-18 19:24:16 +04:00
|
|
|
nsBidiLevel level = nsBidiPresUtils::BidiLevelFromStyle(StyleContext());
|
2011-04-13 13:23:49 +04:00
|
|
|
if (mAccessKeyInfo && mAccessKeyInfo->mAccesskeyIndex != kNotFound) {
|
|
|
|
// We let the RenderText function calculate the mnemonic's
|
|
|
|
// underline position for us.
|
|
|
|
nsBidiPositionResolve posResolve;
|
|
|
|
posResolve.logicalIndex = mAccessKeyInfo->mAccesskeyIndex;
|
2013-11-18 19:24:16 +04:00
|
|
|
rv = nsBidiPresUtils::RenderText(mCroppedTitle.get(), mCroppedTitle.Length(), level,
|
2011-04-13 13:23:49 +04:00
|
|
|
presContext, aRenderingContext,
|
2015-12-16 00:56:41 +03:00
|
|
|
refDrawTarget, *fontMet,
|
2015-03-03 19:38:31 +03:00
|
|
|
baselinePt.x, baselinePt.y,
|
2011-04-13 13:23:49 +04:00
|
|
|
&posResolve,
|
|
|
|
1);
|
|
|
|
mAccessKeyInfo->mBeforeWidth = posResolve.visualLeftTwips;
|
|
|
|
mAccessKeyInfo->mAccessWidth = posResolve.visualWidth;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-18 19:24:16 +04:00
|
|
|
rv = nsBidiPresUtils::RenderText(mCroppedTitle.get(), mCroppedTitle.Length(), level,
|
2011-04-13 13:23:49 +04:00
|
|
|
presContext, aRenderingContext,
|
2015-12-16 00:56:41 +03:00
|
|
|
refDrawTarget, *fontMet,
|
2015-03-03 19:38:31 +03:00
|
|
|
baselinePt.x, baselinePt.y);
|
2001-11-12 23:51:48 +03:00
|
|
|
}
|
|
|
|
}
|
2014-04-24 05:15:29 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-10-24 19:28:14 +04:00
|
|
|
fontMet->SetTextRunRTL(false);
|
2007-01-23 05:58:55 +03:00
|
|
|
|
2004-10-29 16:28:19 +04:00
|
|
|
if (mAccessKeyInfo && mAccessKeyInfo->mAccesskeyIndex != kNotFound) {
|
|
|
|
// In the simple (non-BiDi) case, we calculate the mnemonic's
|
|
|
|
// underline position by getting the text metric.
|
|
|
|
// XXX are attribute values always two byte?
|
|
|
|
if (mAccessKeyInfo->mAccesskeyIndex > 0)
|
2014-10-24 19:28:13 +04:00
|
|
|
mAccessKeyInfo->mBeforeWidth = nsLayoutUtils::
|
|
|
|
AppUnitWidthOfString(mCroppedTitle.get(),
|
|
|
|
mAccessKeyInfo->mAccesskeyIndex,
|
2015-12-16 00:56:41 +03:00
|
|
|
*fontMet, refDrawTarget);
|
2004-10-29 16:28:19 +04:00
|
|
|
else
|
|
|
|
mAccessKeyInfo->mBeforeWidth = 0;
|
|
|
|
}
|
|
|
|
|
2011-04-08 05:05:25 +04:00
|
|
|
fontMet->DrawString(mCroppedTitle.get(), mCroppedTitle.Length(),
|
2015-03-03 19:38:31 +03:00
|
|
|
baselinePt.x, baselinePt.y, &aRenderingContext,
|
2015-12-16 00:56:41 +03:00
|
|
|
refDrawTarget);
|
2004-10-29 16:28:19 +04:00
|
|
|
}
|
2000-10-08 09:56:55 +04:00
|
|
|
|
|
|
|
if (mAccessKeyInfo && mAccessKeyInfo->mAccesskeyIndex != kNotFound) {
|
2014-10-19 14:55:36 +04:00
|
|
|
nsRect r(aTextRect.x + mAccessKeyInfo->mBeforeWidth,
|
|
|
|
aTextRect.y + mAccessKeyInfo->mAccessOffset,
|
|
|
|
mAccessKeyInfo->mAccessWidth,
|
|
|
|
mAccessKeyInfo->mAccessUnderlineSize);
|
2014-10-22 15:29:06 +04:00
|
|
|
Rect devPxRect =
|
|
|
|
NSRectToSnappedRect(r, appUnitsPerDevPixel, *drawTarget);
|
2014-10-19 14:55:36 +04:00
|
|
|
drawTarget->FillRect(devPxRect, color);
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
2008-10-01 09:46:18 +04:00
|
|
|
|
|
|
|
// Strikeout is drawn on top of the text, per
|
|
|
|
// http://www.w3.org/TR/CSS21/zindex.html point 7.2.1.4.1.1.
|
2015-12-01 01:02:26 +03:00
|
|
|
if ((decorations & NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH) &&
|
2011-04-23 09:13:09 +04:00
|
|
|
strikeStyle != NS_STYLE_TEXT_DECORATION_STYLE_NONE) {
|
2008-10-01 09:46:18 +04:00
|
|
|
fontMet->GetStrikeout(offset, size);
|
|
|
|
gfxFloat offsetPixel = presContext->AppUnitsToGfxUnits(offset);
|
|
|
|
gfxFloat sizePixel = presContext->AppUnitsToGfxUnits(size);
|
2014-10-26 03:15:26 +03:00
|
|
|
nsCSSRendering::PaintDecorationLine(this, *drawTarget, ToRect(dirtyRect),
|
|
|
|
strikeColor,
|
2015-11-09 07:19:00 +03:00
|
|
|
pt, xInFrame, Size(width, sizePixel), ascentPixel,
|
2012-07-04 09:59:50 +04:00
|
|
|
offsetPixel, NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH,
|
2014-10-08 13:32:55 +04:00
|
|
|
strikeStyle, vertical);
|
2008-10-01 09:46:18 +04:00
|
|
|
}
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
|
|
|
|
2000-10-08 09:56:55 +04:00
|
|
|
void
|
2015-12-16 00:56:41 +03:00
|
|
|
nsTextBoxFrame::CalculateUnderline(DrawTarget* aDrawTarget,
|
2014-10-24 19:28:14 +04:00
|
|
|
nsFontMetrics& aFontMetrics)
|
2000-10-08 09:56:55 +04:00
|
|
|
{
|
|
|
|
if (mAccessKeyInfo && mAccessKeyInfo->mAccesskeyIndex != kNotFound) {
|
2004-10-29 16:28:19 +04:00
|
|
|
// Calculate all fields of mAccessKeyInfo which
|
2007-01-23 05:58:55 +03:00
|
|
|
// are the same for both BiDi and non-BiDi frames.
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *titleString = mCroppedTitle.get();
|
2014-10-24 19:28:14 +04:00
|
|
|
aFontMetrics.SetTextRunRTL(false);
|
2014-10-24 19:28:13 +04:00
|
|
|
mAccessKeyInfo->mAccessWidth = nsLayoutUtils::
|
|
|
|
AppUnitWidthOfString(titleString[mAccessKeyInfo->mAccesskeyIndex],
|
2015-12-16 00:56:41 +03:00
|
|
|
aFontMetrics, aDrawTarget);
|
2000-02-17 02:00:52 +03:00
|
|
|
|
|
|
|
nscoord offset, baseline;
|
2014-10-24 19:28:14 +04:00
|
|
|
aFontMetrics.GetUnderline(offset, mAccessKeyInfo->mAccessUnderlineSize);
|
|
|
|
baseline = aFontMetrics.MaxAscent();
|
2000-02-17 02:00:52 +03:00
|
|
|
mAccessKeyInfo->mAccessOffset = baseline - offset;
|
2000-10-08 09:56:55 +04:00
|
|
|
}
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nscoord
|
2015-12-07 04:15:53 +03:00
|
|
|
nsTextBoxFrame::CalculateTitleForWidth(nsRenderingContext& aRenderingContext,
|
2000-10-08 09:56:55 +04:00
|
|
|
nscoord aWidth)
|
2000-02-17 02:00:52 +03:00
|
|
|
{
|
2015-12-16 00:56:41 +03:00
|
|
|
DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
|
|
|
|
|
2013-03-01 08:06:16 +04:00
|
|
|
if (mTitle.IsEmpty()) {
|
|
|
|
mCroppedTitle.Truncate();
|
2011-01-03 04:48:09 +03:00
|
|
|
return 0;
|
2013-03-01 08:06:16 +04:00
|
|
|
}
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFontMetrics> fm;
|
2011-08-14 21:08:04 +04:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2000-10-08 09:56:55 +04:00
|
|
|
// see if the text will completely fit in the width given
|
2014-10-26 20:57:49 +03:00
|
|
|
nscoord titleWidth =
|
|
|
|
nsLayoutUtils::AppUnitWidthOfStringBidi(mTitle, this, *fm,
|
|
|
|
aRenderingContext);
|
2011-01-03 04:48:09 +03:00
|
|
|
if (titleWidth <= aWidth) {
|
2000-10-08 09:56:55 +04:00
|
|
|
mCroppedTitle = mTitle;
|
2015-04-15 23:00:29 +03:00
|
|
|
if (HasRTLChars(mTitle) ||
|
|
|
|
StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
|
2001-05-15 15:58:40 +04:00
|
|
|
mState |= NS_FRAME_IS_BIDI;
|
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
return titleWidth; // fits, done.
|
2000-10-08 09:56:55 +04:00
|
|
|
}
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2008-01-27 02:00:19 +03:00
|
|
|
const nsDependentString& kEllipsis = nsContentUtils::GetLocalizedEllipsis();
|
2000-10-08 09:56:55 +04:00
|
|
|
// start with an ellipsis
|
2007-11-19 13:17:17 +03:00
|
|
|
mCroppedTitle.Assign(kEllipsis);
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2000-10-08 09:56:55 +04:00
|
|
|
// see if the width is even smaller than the ellipsis
|
|
|
|
// if so, clear the text (XXX set as many '.' as we can?).
|
2014-10-24 19:28:14 +04:00
|
|
|
fm->SetTextRunRTL(false);
|
|
|
|
titleWidth = nsLayoutUtils::AppUnitWidthOfString(kEllipsis, *fm,
|
2015-12-16 00:56:41 +03:00
|
|
|
drawTarget);
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
if (titleWidth > aWidth) {
|
2000-10-08 09:56:55 +04:00
|
|
|
mCroppedTitle.SetLength(0);
|
2011-01-03 04:48:09 +03:00
|
|
|
return 0;
|
2000-10-08 09:56:55 +04:00
|
|
|
}
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2000-10-08 09:56:55 +04:00
|
|
|
// if the ellipsis fits perfectly, no use in trying to insert
|
2011-01-03 04:48:09 +03:00
|
|
|
if (titleWidth == aWidth)
|
|
|
|
return titleWidth;
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
aWidth -= titleWidth;
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2004-05-18 15:01:49 +04:00
|
|
|
// XXX: This whole block should probably take surrogates into account
|
2007-01-23 05:58:55 +03:00
|
|
|
// XXX and clusters!
|
2000-10-08 09:56:55 +04:00
|
|
|
// ok crop things
|
2000-02-17 02:00:52 +03:00
|
|
|
switch (mCropType)
|
|
|
|
{
|
2000-10-08 09:56:55 +04:00
|
|
|
case CropNone:
|
|
|
|
case CropRight:
|
|
|
|
{
|
|
|
|
nscoord cwidth;
|
|
|
|
nscoord twidth = 0;
|
|
|
|
int length = mTitle.Length();
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < length; ++i) {
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t ch = mTitle.CharAt(i);
|
2007-01-23 05:58:55 +03:00
|
|
|
// still in LTR mode
|
2014-10-24 19:28:14 +04:00
|
|
|
cwidth = nsLayoutUtils::AppUnitWidthOfString(ch, *fm,
|
2015-12-16 00:56:41 +03:00
|
|
|
drawTarget);
|
2000-10-08 09:56:55 +04:00
|
|
|
if (twidth + cwidth > aWidth)
|
|
|
|
break;
|
|
|
|
|
|
|
|
twidth += cwidth;
|
2004-07-04 14:51:33 +04:00
|
|
|
if (UCS2_CHAR_IS_BIDI(ch) ) {
|
2001-05-15 15:58:40 +04:00
|
|
|
mState |= NS_FRAME_IS_BIDI;
|
|
|
|
}
|
2000-10-08 09:56:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0)
|
2011-01-03 04:48:09 +03:00
|
|
|
return titleWidth;
|
2000-10-08 09:56:55 +04:00
|
|
|
|
|
|
|
// insert what character we can in.
|
|
|
|
nsAutoString title( mTitle );
|
|
|
|
title.Truncate(i);
|
|
|
|
mCroppedTitle.Insert(title, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CropLeft:
|
|
|
|
{
|
|
|
|
nscoord cwidth;
|
|
|
|
nscoord twidth = 0;
|
|
|
|
int length = mTitle.Length();
|
|
|
|
int i;
|
|
|
|
for (i=length-1; i >= 0; --i) {
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t ch = mTitle.CharAt(i);
|
2014-10-24 19:28:14 +04:00
|
|
|
cwidth = nsLayoutUtils::AppUnitWidthOfString(ch, *fm,
|
2015-12-16 00:56:41 +03:00
|
|
|
drawTarget);
|
2000-10-08 09:56:55 +04:00
|
|
|
if (twidth + cwidth > aWidth)
|
|
|
|
break;
|
|
|
|
|
|
|
|
twidth += cwidth;
|
2004-07-04 14:51:33 +04:00
|
|
|
if (UCS2_CHAR_IS_BIDI(ch) ) {
|
2001-05-15 15:58:40 +04:00
|
|
|
mState |= NS_FRAME_IS_BIDI;
|
|
|
|
}
|
2000-10-08 09:56:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == length-1)
|
2011-01-03 04:48:09 +03:00
|
|
|
return titleWidth;
|
2000-10-08 09:56:55 +04:00
|
|
|
|
|
|
|
nsAutoString copy;
|
|
|
|
mTitle.Right(copy, length-1-i);
|
|
|
|
mCroppedTitle += copy;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CropCenter:
|
|
|
|
{
|
2007-01-23 05:58:55 +03:00
|
|
|
nscoord stringWidth =
|
2014-10-26 20:57:49 +03:00
|
|
|
nsLayoutUtils::AppUnitWidthOfStringBidi(mTitle, this, *fm,
|
|
|
|
aRenderingContext);
|
2001-07-15 04:10:10 +04:00
|
|
|
if (stringWidth <= aWidth) {
|
|
|
|
// the entire string will fit in the maximum width
|
|
|
|
mCroppedTitle.Insert(mTitle, 0);
|
|
|
|
break;
|
|
|
|
}
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2001-07-15 04:10:10 +04:00
|
|
|
// determine how much of the string will fit in the max width
|
|
|
|
nscoord charWidth = 0;
|
|
|
|
nscoord totalWidth = 0;
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t ch;
|
2001-07-15 04:10:10 +04:00
|
|
|
int leftPos, rightPos;
|
|
|
|
nsAutoString leftString, rightString;
|
|
|
|
|
|
|
|
rightPos = mTitle.Length() - 1;
|
2014-10-24 19:28:14 +04:00
|
|
|
fm->SetTextRunRTL(false);
|
2001-07-15 04:10:10 +04:00
|
|
|
for (leftPos = 0; leftPos <= rightPos;) {
|
|
|
|
// look at the next character on the left end
|
|
|
|
ch = mTitle.CharAt(leftPos);
|
2014-10-24 19:28:14 +04:00
|
|
|
charWidth = nsLayoutUtils::AppUnitWidthOfString(ch, *fm,
|
2015-12-16 00:56:41 +03:00
|
|
|
drawTarget);
|
2001-07-15 04:10:10 +04:00
|
|
|
totalWidth += charWidth;
|
|
|
|
if (totalWidth > aWidth)
|
|
|
|
// greater than the allowable width
|
2000-10-08 09:56:55 +04:00
|
|
|
break;
|
2001-07-15 04:10:10 +04:00
|
|
|
leftString.Insert(ch, leftString.Length());
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2004-07-04 14:51:33 +04:00
|
|
|
if (UCS2_CHAR_IS_BIDI(ch))
|
2001-07-15 04:10:10 +04:00
|
|
|
mState |= NS_FRAME_IS_BIDI;
|
|
|
|
|
|
|
|
// look at the next character on the right end
|
|
|
|
if (rightPos > leftPos) {
|
|
|
|
// haven't looked at this character yet
|
|
|
|
ch = mTitle.CharAt(rightPos);
|
2014-10-24 19:28:13 +04:00
|
|
|
charWidth =
|
2014-10-24 19:28:14 +04:00
|
|
|
nsLayoutUtils::AppUnitWidthOfString(ch, *fm,
|
2015-12-16 00:56:41 +03:00
|
|
|
drawTarget);
|
2001-07-15 04:10:10 +04:00
|
|
|
totalWidth += charWidth;
|
|
|
|
if (totalWidth > aWidth)
|
|
|
|
// greater than the allowable width
|
|
|
|
break;
|
|
|
|
rightString.Insert(ch, 0);
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2004-07-04 14:51:33 +04:00
|
|
|
if (UCS2_CHAR_IS_BIDI(ch))
|
2001-07-15 04:10:10 +04:00
|
|
|
mState |= NS_FRAME_IS_BIDI;
|
2001-05-15 15:58:40 +04:00
|
|
|
}
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2001-07-15 04:10:10 +04:00
|
|
|
// look at the next two characters
|
|
|
|
leftPos++;
|
|
|
|
rightPos--;
|
|
|
|
}
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2007-11-19 13:17:17 +03:00
|
|
|
mCroppedTitle = leftString + kEllipsis + rightString;
|
2000-10-08 09:56:55 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
|
|
|
|
2014-10-26 20:57:49 +03:00
|
|
|
return nsLayoutUtils::AppUnitWidthOfStringBidi(mCroppedTitle, this, *fm,
|
|
|
|
aRenderingContext);
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
|
|
|
|
2007-11-19 13:17:17 +03:00
|
|
|
#define OLD_ELLIPSIS NS_LITERAL_STRING("...")
|
|
|
|
|
2000-10-08 09:56:55 +04:00
|
|
|
// the following block is to append the accesskey to mTitle if there is an accesskey
|
|
|
|
// but the mTitle doesn't have the character
|
2000-02-17 02:00:52 +03:00
|
|
|
void
|
2000-10-08 09:56:55 +04:00
|
|
|
nsTextBoxFrame::UpdateAccessTitle()
|
2000-02-17 02:00:52 +03:00
|
|
|
{
|
2006-02-10 16:23:50 +03:00
|
|
|
/*
|
|
|
|
* Note that if you change appending access key label spec,
|
|
|
|
* you need to maintain same logic in following methods. See bug 324159.
|
|
|
|
* toolkit/content/commonDialog.js (setLabelForNode)
|
|
|
|
* toolkit/content/widgets/text.xml (formatAccessKey)
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t menuAccessKey;
|
2000-10-08 09:56:55 +04:00
|
|
|
nsMenuBarListener::GetMenuAccessKey(&menuAccessKey);
|
2006-01-21 08:04:28 +03:00
|
|
|
if (!menuAccessKey || mAccessKey.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!AlwaysAppendAccessKey() &&
|
|
|
|
FindInReadable(mAccessKey, mTitle, nsCaseInsensitiveStringComparator()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsAutoString accessKeyLabel;
|
|
|
|
accessKeyLabel += '(';
|
|
|
|
accessKeyLabel += mAccessKey;
|
|
|
|
ToUpperCase(accessKeyLabel);
|
|
|
|
accessKeyLabel += ')';
|
|
|
|
|
|
|
|
if (mTitle.IsEmpty()) {
|
|
|
|
mTitle = accessKeyLabel;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-27 02:00:19 +03:00
|
|
|
const nsDependentString& kEllipsis = nsContentUtils::GetLocalizedEllipsis();
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t offset = mTitle.Length();
|
2007-12-13 08:51:40 +03:00
|
|
|
if (StringEndsWith(mTitle, kEllipsis)) {
|
|
|
|
offset -= kEllipsis.Length();
|
|
|
|
} else if (StringEndsWith(mTitle, OLD_ELLIPSIS)) {
|
2007-11-19 13:17:17 +03:00
|
|
|
// Try to check with our old ellipsis (for old addons)
|
2007-12-13 08:51:40 +03:00
|
|
|
offset -= OLD_ELLIPSIS.Length();
|
|
|
|
} else {
|
|
|
|
// Try to check with
|
|
|
|
// our default ellipsis (for non-localized addons) or ':'
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t kLastChar = mTitle.Last();
|
|
|
|
if (kLastChar == char16_t(0x2026) || kLastChar == char16_t(':'))
|
2006-01-21 08:04:28 +03:00
|
|
|
offset--;
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
2006-01-21 08:04:28 +03:00
|
|
|
|
2007-12-13 08:51:40 +03:00
|
|
|
if (InsertSeparatorBeforeAccessKey() &&
|
2010-05-12 04:30:42 +04:00
|
|
|
offset > 0 && !NS_IS_SPACE(mTitle[offset - 1])) {
|
2007-12-13 08:51:40 +03:00
|
|
|
mTitle.Insert(' ', offset);
|
2006-01-21 08:04:28 +03:00
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
|
2007-12-13 08:51:40 +03:00
|
|
|
mTitle.Insert(accessKeyLabel, offset);
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
|
|
|
|
2000-10-08 09:56:55 +04:00
|
|
|
void
|
|
|
|
nsTextBoxFrame::UpdateAccessIndex()
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t menuAccessKey;
|
2000-10-08 09:56:55 +04:00
|
|
|
nsMenuBarListener::GetMenuAccessKey(&menuAccessKey);
|
|
|
|
if (menuAccessKey) {
|
|
|
|
if (mAccessKey.IsEmpty()) {
|
|
|
|
if (mAccessKeyInfo) {
|
|
|
|
delete mAccessKeyInfo;
|
2012-07-30 18:20:58 +04:00
|
|
|
mAccessKeyInfo = nullptr;
|
2000-10-08 09:56:55 +04:00
|
|
|
}
|
|
|
|
} else {
|
2003-12-21 07:04:05 +03:00
|
|
|
if (!mAccessKeyInfo) {
|
2000-10-08 09:56:55 +04:00
|
|
|
mAccessKeyInfo = new nsAccessKeyInfo();
|
2003-12-21 07:04:05 +03:00
|
|
|
if (!mAccessKeyInfo)
|
|
|
|
return;
|
|
|
|
}
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2002-03-19 09:46:56 +03:00
|
|
|
nsAString::const_iterator start, end;
|
|
|
|
|
|
|
|
mCroppedTitle.BeginReading(start);
|
|
|
|
mCroppedTitle.EndReading(end);
|
|
|
|
|
|
|
|
// remember the beginning of the string
|
|
|
|
nsAString::const_iterator originalStart = start;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool found;
|
2001-10-20 00:56:29 +04:00
|
|
|
if (!AlwaysAppendAccessKey()) {
|
2002-03-19 09:46:56 +03:00
|
|
|
// not appending access key - do case-sensitive search
|
|
|
|
// first
|
|
|
|
found = FindInReadable(mAccessKey, start, end);
|
|
|
|
if (!found) {
|
2001-06-08 07:25:44 +04:00
|
|
|
// didn't find it - perform a case-insensitive search
|
2002-03-19 09:46:56 +03:00
|
|
|
start = originalStart;
|
|
|
|
found = FindInReadable(mAccessKey, start, end,
|
|
|
|
nsCaseInsensitiveStringComparator());
|
2001-06-08 07:25:44 +04:00
|
|
|
}
|
2001-04-17 05:58:00 +04:00
|
|
|
} else {
|
2002-03-19 09:46:56 +03:00
|
|
|
found = RFindInReadable(mAccessKey, start, end,
|
|
|
|
nsCaseInsensitiveStringComparator());
|
2001-04-17 05:58:00 +04:00
|
|
|
}
|
2002-03-19 09:46:56 +03:00
|
|
|
|
|
|
|
if (found)
|
|
|
|
mAccessKeyInfo->mAccesskeyIndex = Distance(originalStart, start);
|
|
|
|
else
|
|
|
|
mAccessKeyInfo->mAccesskeyIndex = kNotFound;
|
2000-10-08 09:56:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-17 02:00:52 +03:00
|
|
|
|
2014-05-24 01:32:37 +04:00
|
|
|
void
|
|
|
|
nsTextBoxFrame::RecomputeTitle()
|
|
|
|
{
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, mTitle);
|
|
|
|
|
|
|
|
// This doesn't handle language-specific uppercasing/lowercasing
|
|
|
|
// rules, unlike textruns.
|
|
|
|
uint8_t textTransform = StyleText()->mTextTransform;
|
|
|
|
if (textTransform == NS_STYLE_TEXT_TRANSFORM_UPPERCASE) {
|
|
|
|
ToUpperCase(mTitle);
|
|
|
|
} else if (textTransform == NS_STYLE_TEXT_TRANSFORM_LOWERCASE) {
|
|
|
|
ToLowerCase(mTitle);
|
|
|
|
}
|
|
|
|
// We can't handle NS_STYLE_TEXT_TRANSFORM_CAPITALIZE because we
|
|
|
|
// have no clue about word boundaries here. We also don't handle
|
|
|
|
// NS_STYLE_TEXT_TRANSFORM_FULLWIDTH.
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTextBoxFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
|
|
|
|
{
|
|
|
|
if (!aOldStyleContext) {
|
|
|
|
// We're just being initialized
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsStyleText* oldTextStyle = aOldStyleContext->PeekStyleText();
|
|
|
|
// We should really have oldTextStyle here, since we asked for our
|
|
|
|
// nsStyleText during Init(), but if it's not there for some reason
|
|
|
|
// just assume the worst and recompute mTitle.
|
|
|
|
if (!oldTextStyle ||
|
|
|
|
oldTextStyle->mTextTransform != StyleText()->mTextTransform) {
|
|
|
|
RecomputeTitle();
|
|
|
|
UpdateAccessTitle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-17 02:00:52 +03:00
|
|
|
NS_IMETHODIMP
|
2000-07-08 02:24:06 +04:00
|
|
|
nsTextBoxFrame::DoLayout(nsBoxLayoutState& aBoxLayoutState)
|
2000-02-17 02:00:52 +03:00
|
|
|
{
|
2007-09-04 12:46:50 +04:00
|
|
|
if (mNeedsReflowCallback) {
|
|
|
|
nsIReflowCallback* cb = new nsAsyncAccesskeyUpdate(this);
|
|
|
|
if (cb) {
|
|
|
|
PresContext()->PresShell()->PostReflowCallback(cb);
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsReflowCallback = false;
|
2007-09-04 12:46:50 +04:00
|
|
|
}
|
|
|
|
|
2008-10-01 04:57:51 +04:00
|
|
|
nsresult rv = nsLeafBoxFrame::DoLayout(aBoxLayoutState);
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
CalcDrawRect(*aBoxLayoutState.GetRenderingContext());
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleText* textStyle = StyleText();
|
2012-04-27 04:24:54 +04:00
|
|
|
|
2012-04-30 04:34:09 +04:00
|
|
|
nsRect scrollBounds(nsPoint(0, 0), GetSize());
|
2012-04-27 04:24:54 +04:00
|
|
|
nsRect textRect = mTextDrawRect;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFontMetrics> fontMet;
|
2012-04-27 04:24:54 +04:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
|
|
|
|
nsBoundingMetrics metrics =
|
2012-04-30 04:34:09 +04:00
|
|
|
fontMet->GetInkBoundsForVisualOverflow(mCroppedTitle.get(),
|
|
|
|
mCroppedTitle.Length(),
|
2015-12-16 00:56:41 +03:00
|
|
|
aBoxLayoutState.GetRenderingContext()->GetDrawTarget());
|
2012-04-27 04:24:54 +04:00
|
|
|
|
2015-03-03 19:38:31 +03:00
|
|
|
WritingMode wm = GetWritingMode();
|
2015-07-16 12:07:57 +03:00
|
|
|
LogicalRect tr(wm, textRect, GetSize());
|
2015-03-03 19:38:31 +03:00
|
|
|
|
|
|
|
tr.IStart(wm) -= metrics.leftBearing;
|
|
|
|
tr.ISize(wm) = metrics.width;
|
2012-04-27 04:24:54 +04:00
|
|
|
// In DrawText() we always draw with the baseline at MaxAscent() (relative to mTextDrawRect),
|
2015-03-03 19:38:31 +03:00
|
|
|
tr.BStart(wm) += fontMet->MaxAscent() - metrics.ascent;
|
|
|
|
tr.BSize(wm) = metrics.ascent + metrics.descent;
|
|
|
|
|
2015-07-16 12:07:57 +03:00
|
|
|
textRect = tr.GetPhysicalRect(wm, GetSize());
|
2012-04-27 04:24:54 +04:00
|
|
|
|
2012-04-30 04:34:09 +04:00
|
|
|
// Our scrollable overflow is our bounds; our visual overflow may
|
|
|
|
// extend beyond that.
|
|
|
|
nsRect visualBounds;
|
|
|
|
visualBounds.UnionRect(scrollBounds, textRect);
|
|
|
|
nsOverflowAreas overflow(visualBounds, scrollBounds);
|
2012-04-27 04:24:54 +04:00
|
|
|
|
2008-10-01 04:57:51 +04:00
|
|
|
if (textStyle->mTextShadow) {
|
2012-04-30 04:34:09 +04:00
|
|
|
// text-shadow extends our visual but not scrollable bounds
|
2010-10-07 08:25:45 +04:00
|
|
|
nsRect &vis = overflow.VisualOverflow();
|
2011-01-03 04:48:09 +03:00
|
|
|
vis.UnionRect(vis, nsLayoutUtils::GetTextShadowRectsUnion(mTextDrawRect, this));
|
2008-10-01 04:57:51 +04:00
|
|
|
}
|
2012-04-27 04:24:54 +04:00
|
|
|
FinishAndStoreOverflow(overflow, GetSize());
|
2011-01-03 04:48:09 +03:00
|
|
|
|
2008-10-01 04:57:51 +04:00
|
|
|
return rv;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRect
|
|
|
|
nsTextBoxFrame::GetComponentAlphaBounds()
|
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
if (StyleText()->mTextShadow) {
|
2012-07-23 07:00:36 +04:00
|
|
|
return GetVisualOverflowRectRelativeToSelf();
|
|
|
|
}
|
|
|
|
return mTextDrawRect;
|
2011-01-03 04:48:09 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-11-26 01:59:06 +03:00
|
|
|
nsTextBoxFrame::ComputesOwnOverflowArea()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-11-26 01:59:06 +03:00
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
/* virtual */ void
|
2014-07-24 21:03:26 +04:00
|
|
|
nsTextBoxFrame::MarkIntrinsicISizesDirty()
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsRecalc = true;
|
2014-07-24 21:03:26 +04:00
|
|
|
nsTextBoxFrameSuper::MarkIntrinsicISizesDirty();
|
2000-10-08 09:56:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-12-07 04:15:53 +03:00
|
|
|
nsTextBoxFrame::GetTextSize(nsRenderingContext& aRenderingContext,
|
2011-04-08 08:18:43 +04:00
|
|
|
const nsString& aString,
|
|
|
|
nsSize& aSize, nscoord& aAscent)
|
2000-10-08 09:56:55 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFontMetrics> fontMet;
|
2007-08-07 23:07:43 +04:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
|
2011-04-08 08:18:43 +04:00
|
|
|
aSize.height = fontMet->MaxHeight();
|
2007-01-23 05:58:55 +03:00
|
|
|
aSize.width =
|
2014-10-26 20:57:49 +03:00
|
|
|
nsLayoutUtils::AppUnitWidthOfStringBidi(aString, this, *fontMet,
|
|
|
|
aRenderingContext);
|
2011-04-08 08:18:43 +04:00
|
|
|
aAscent = fontMet->MaxAscent();
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTextBoxFrame::CalcTextSize(nsBoxLayoutState& aBoxLayoutState)
|
|
|
|
{
|
2015-12-07 04:15:53 +03:00
|
|
|
if (mNeedsRecalc) {
|
2000-10-08 09:56:55 +04:00
|
|
|
nsSize size;
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* rendContext = aBoxLayoutState.GetRenderingContext();
|
2000-10-08 09:56:55 +04:00
|
|
|
if (rendContext) {
|
2015-12-07 04:15:53 +03:00
|
|
|
GetTextSize(*rendContext, mTitle, size, mAscent);
|
2015-03-03 19:38:31 +03:00
|
|
|
if (GetWritingMode().IsVertical()) {
|
|
|
|
Swap(size.width, size.height);
|
|
|
|
}
|
2000-10-08 09:56:55 +04:00
|
|
|
mTextSize = size;
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsRecalc = false;
|
2000-10-08 09:56:55 +04:00
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
void
|
2011-04-08 05:04:40 +04:00
|
|
|
nsTextBoxFrame::CalcDrawRect(nsRenderingContext &aRenderingContext)
|
2008-10-01 04:57:51 +04:00
|
|
|
{
|
2015-03-03 19:38:31 +03:00
|
|
|
WritingMode wm = GetWritingMode();
|
|
|
|
|
|
|
|
LogicalRect textRect(wm, LogicalPoint(wm, 0, 0), GetLogicalSize(wm));
|
2008-10-21 11:43:58 +04:00
|
|
|
nsMargin borderPadding;
|
|
|
|
GetBorderAndPadding(borderPadding);
|
2015-03-03 19:38:31 +03:00
|
|
|
textRect.Deflate(wm, LogicalMargin(wm, borderPadding));
|
2011-01-03 04:48:09 +03:00
|
|
|
|
2008-10-01 04:57:51 +04:00
|
|
|
// determine (cropped) title and underline position
|
2015-03-03 19:38:31 +03:00
|
|
|
// determine (cropped) title which fits in aRect, and its width
|
|
|
|
// (where "width" is the text measure along its baseline, i.e. actually
|
|
|
|
// a physical height in vertical writing modes)
|
2011-01-03 04:48:09 +03:00
|
|
|
nscoord titleWidth =
|
2015-12-07 04:15:53 +03:00
|
|
|
CalculateTitleForWidth(aRenderingContext, textRect.ISize(wm));
|
2013-03-01 08:06:16 +04:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
// Make sure to update the accessible tree in case when cropped title is
|
|
|
|
// changed.
|
|
|
|
nsAccessibilityService* accService = GetAccService();
|
|
|
|
if (accService) {
|
|
|
|
accService->UpdateLabelValue(PresContext()->PresShell(), mContent,
|
|
|
|
mCroppedTitle);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
// determine if and at which position to put the underline
|
|
|
|
UpdateAccessIndex();
|
2008-10-01 04:57:51 +04:00
|
|
|
|
|
|
|
// make the rect as small as our (cropped) text.
|
2015-03-03 19:38:31 +03:00
|
|
|
nscoord outerISize = textRect.ISize(wm);
|
|
|
|
textRect.ISize(wm) = titleWidth;
|
2008-10-01 04:57:51 +04:00
|
|
|
|
|
|
|
// Align our text within the overall rect by checking our text-align property.
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleText* textStyle = StyleText();
|
2015-03-03 19:38:31 +03:00
|
|
|
if (textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_CENTER) {
|
|
|
|
textRect.IStart(wm) += (outerISize - textRect.ISize(wm)) / 2;
|
|
|
|
} else if (textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_END ||
|
|
|
|
(textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_LEFT &&
|
|
|
|
!wm.IsBidiLTR()) ||
|
|
|
|
(textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_RIGHT &&
|
|
|
|
wm.IsBidiLTR())) {
|
|
|
|
textRect.IStart(wm) += (outerISize - textRect.ISize(wm));
|
2008-10-01 04:57:51 +04:00
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
|
2015-07-16 12:07:57 +03:00
|
|
|
mTextDrawRect = textRect.GetPhysicalRect(wm, GetSize());
|
2008-10-01 04:57:51 +04:00
|
|
|
}
|
|
|
|
|
2000-02-17 02:00:52 +03:00
|
|
|
/**
|
|
|
|
* Ok return our dimensions
|
|
|
|
*/
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize
|
|
|
|
nsTextBoxFrame::GetPrefSize(nsBoxLayoutState& aBoxLayoutState)
|
2000-02-17 02:00:52 +03:00
|
|
|
{
|
2000-10-08 09:56:55 +04:00
|
|
|
CalcTextSize(aBoxLayoutState);
|
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize size = mTextSize;
|
|
|
|
DISPLAY_PREF_SIZE(this, size);
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
AddBorderAndPadding(size);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool widthSet, heightSet;
|
2012-08-06 07:00:57 +04:00
|
|
|
nsIFrame::AddCSSPrefSize(this, size, widthSet, heightSet);
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
return size;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ok return our dimensions
|
|
|
|
*/
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize
|
|
|
|
nsTextBoxFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2000-10-08 09:56:55 +04:00
|
|
|
CalcTextSize(aBoxLayoutState);
|
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize size = mTextSize;
|
|
|
|
DISPLAY_MIN_SIZE(this, size);
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
// if there is cropping our min width becomes our border and padding
|
2015-03-03 19:38:31 +03:00
|
|
|
if (mCropType != CropNone) {
|
|
|
|
if (GetWritingMode().IsVertical()) {
|
|
|
|
size.height = 0;
|
|
|
|
} else {
|
|
|
|
size.width = 0;
|
|
|
|
}
|
|
|
|
}
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
AddBorderAndPadding(size);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool widthSet, heightSet;
|
2012-08-06 07:00:57 +04:00
|
|
|
nsIFrame::AddCSSMinSize(aBoxLayoutState, this, size, widthSet, heightSet);
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
return size;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2007-02-22 21:05:14 +03:00
|
|
|
nscoord
|
|
|
|
nsTextBoxFrame::GetBoxAscent(nsBoxLayoutState& aBoxLayoutState)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2000-10-08 09:56:55 +04:00
|
|
|
CalcTextSize(aBoxLayoutState);
|
|
|
|
|
2007-02-22 21:05:14 +03:00
|
|
|
nscoord ascent = mAscent;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2000-10-08 09:56:55 +04:00
|
|
|
nsMargin m(0,0,0,0);
|
|
|
|
GetBorderAndPadding(m);
|
2015-03-03 19:38:31 +03:00
|
|
|
|
|
|
|
WritingMode wm = GetWritingMode();
|
|
|
|
ascent += LogicalMargin(wm, m).BStart(wm);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2007-02-22 21:05:14 +03:00
|
|
|
return ascent;
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2001-11-14 04:33:42 +03:00
|
|
|
nsTextBoxFrame::GetFrameName(nsAString& aResult) const
|
2000-02-17 02:00:52 +03:00
|
|
|
{
|
2005-12-16 01:26:18 +03:00
|
|
|
MakeFrameName(NS_LITERAL_STRING("TextBox"), aResult);
|
2001-11-14 04:33:42 +03:00
|
|
|
aResult += NS_LITERAL_STRING("[value=") + mTitle + NS_LITERAL_STRING("]");
|
2000-10-08 09:56:55 +04:00
|
|
|
return NS_OK;
|
2000-02-17 02:00:52 +03:00
|
|
|
}
|
2001-09-15 04:45:54 +04:00
|
|
|
#endif
|
2002-02-21 16:39:39 +03:00
|
|
|
|
|
|
|
// If you make changes to this function, check its counterparts
|
2008-12-29 18:07:38 +03:00
|
|
|
// in nsBoxFrame and nsXULLabelFrame
|
2002-02-21 16:39:39 +03:00
|
|
|
nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
nsTextBoxFrame::RegUnregAccessKey(bool aDoReg)
|
2002-02-21 16:39:39 +03:00
|
|
|
{
|
|
|
|
// if we have no content, we can't do anything
|
|
|
|
if (!mContent)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// check if we have a |control| attribute
|
|
|
|
// do this check first because few elements have control attributes, and we
|
|
|
|
// can weed out most of the elements quickly.
|
|
|
|
|
|
|
|
// XXXjag a side-effect is that we filter out anonymous <label>s
|
|
|
|
// in e.g. <menu>, <menuitem>, <button>. These <label>s inherit
|
|
|
|
// |accesskey| and would otherwise register themselves, overwriting
|
|
|
|
// the content we really meant to be registered.
|
2006-12-26 20:47:52 +03:00
|
|
|
if (!mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::control))
|
2002-02-21 16:39:39 +03:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// see if we even have an access key
|
|
|
|
nsAutoString accessKey;
|
2006-12-26 20:47:52 +03:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
|
2002-02-21 16:39:39 +03:00
|
|
|
|
|
|
|
if (accessKey.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// With a valid PresContext we can get the ESM
|
|
|
|
// and (un)register the access key
|
2014-04-01 08:09:23 +04:00
|
|
|
EventStateManager* esm = PresContext()->EventStateManager();
|
2002-02-21 16:39:39 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t key = accessKey.First();
|
2004-02-27 20:17:37 +03:00
|
|
|
if (aDoReg)
|
2011-04-21 21:35:52 +04:00
|
|
|
esm->RegisterAccessKey(mContent, key);
|
2004-02-27 20:17:37 +03:00
|
|
|
else
|
2011-04-21 21:35:52 +04:00
|
|
|
esm->UnregisterAccessKey(mContent, key);
|
2002-02-21 16:39:39 +03:00
|
|
|
|
2011-04-21 21:35:52 +04:00
|
|
|
return NS_OK;
|
2002-02-21 16:39:39 +03:00
|
|
|
}
|