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
|
|
|
|
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"
|
|
|
|
#include "nsINameSpaceManager.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"
|
2011-04-21 21:35:52 +04:00
|
|
|
#include "nsEventStateManager.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"
|
2013-05-22 20:05:26 +04:00
|
|
|
#include "nsCxPusher.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
|
|
|
|
|
2001-05-15 15:58:40 +04:00
|
|
|
#ifdef IBMBIDI
|
2002-02-19 23:41:32 +03:00
|
|
|
#include "nsBidiUtils.h"
|
2001-05-15 15:58:40 +04:00
|
|
|
#include "nsBidiPresUtils.h"
|
|
|
|
#endif // IBMBIDI
|
|
|
|
|
2011-05-27 08:53:03 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
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
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsTextBoxFrame (aPresShell, 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
|
|
|
}
|
|
|
|
|
2006-03-27 01:30:36 +04:00
|
|
|
nsTextBoxFrame::nsTextBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext):
|
2012-07-30 18:20:58 +04:00
|
|
|
nsLeafBoxFrame(aShell, aContext), mAccessKeyInfo(nullptr), mCropType(CropRight),
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsReflowCallback(false)
|
2000-02-17 02:00:52 +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
|
|
|
MarkIntrinsicWidthsDirty();
|
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
|
2006-03-09 21:55:21 +03:00
|
|
|
nsTextBoxFrame::Init(nsIContent* aContent,
|
2000-10-08 09:56:55 +04:00
|
|
|
nsIFrame* 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);
|
2005-06-28 21:21:21 +04:00
|
|
|
gAlwaysAppendAccessKey = val.Equals(NS_LITERAL_STRING("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
|
|
|
|
2012-07-11 08:03:55 +04:00
|
|
|
class nsAsyncAccesskeyUpdate MOZ_FINAL : public nsIReflowCallback
|
2007-08-10 11:06:13 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsAsyncAccesskeyUpdate(nsIFrame* aFrame) : mWeakFrame(aFrame)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool ReflowFinished()
|
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;
|
|
|
|
}
|
|
|
|
|
2007-12-01 10:22:44 +03:00
|
|
|
virtual void ReflowCallbackCanceled()
|
|
|
|
{
|
|
|
|
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.
|
2007-08-18 04:13:14 +04:00
|
|
|
// Because this method is called by the reflow callback, current context
|
|
|
|
// may not be the right one. Pushing the context of mContent so that
|
|
|
|
// if nsIDOMXULLabelElement is implemented in XBL, we don't get a
|
|
|
|
// security exception.
|
2007-10-01 14:02:32 +04:00
|
|
|
nsCxPusher cx;
|
|
|
|
if (cx.Push(mContent)) {
|
|
|
|
labelElement->GetAccessKey(accesskey);
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(aWeakThis.IsAlive(), false);
|
2007-10-01 14:02:32 +04:00
|
|
|
}
|
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.
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, mTitle);
|
|
|
|
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) {
|
2006-12-26 20:47:52 +03:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, mTitle);
|
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,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx);
|
2012-04-10 15:24:18 +04:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap);
|
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
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
virtual nsRect GetComponentAlphaBounds(nsDisplayListBuilder* aBuilder);
|
2011-01-03 04:48:09 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
virtual void DisableComponentAlpha() { 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
|
|
|
{
|
2011-01-03 04:48:09 +03:00
|
|
|
gfxContextAutoDisableSubpixelAntialiasing disable(aCtx->ThebesContext(),
|
|
|
|
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();
|
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
|
|
|
|
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
|
|
|
|
2011-04-08 05:05:49 +04:00
|
|
|
nsRefPtr<nsFontMetrics> fontMet;
|
2007-08-07 23:07:43 +04:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
|
|
|
|
|
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
|
|
|
|
2007-09-03 19:27:26 +04:00
|
|
|
nscoord baseline =
|
2008-10-01 04:57:51 +04:00
|
|
|
presContext->RoundAppUnitsToNearestDevPixels(aTextRect.y + ascent);
|
2007-12-19 02:01:15 +03:00
|
|
|
nsRefPtr<gfxContext> ctx = aRenderingContext.ThebesContext();
|
2008-10-01 04:57:51 +04:00
|
|
|
gfxPoint pt(presContext->AppUnitsToGfxUnits(aTextRect.x),
|
|
|
|
presContext->AppUnitsToGfxUnits(aTextRect.y));
|
|
|
|
gfxFloat width = presContext->AppUnitsToGfxUnits(aTextRect.width);
|
2007-09-03 19:27:26 +04:00
|
|
|
gfxFloat ascentPixel = presContext->AppUnitsToGfxUnits(ascent);
|
2012-07-04 09:59:50 +04:00
|
|
|
gfxFloat xInFrame = 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
|
|
|
|
|
|
|
// 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.)
|
|
|
|
if (decorations & (NS_FONT_DECORATION_OVERLINE |
|
|
|
|
NS_FONT_DECORATION_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);
|
|
|
|
gfxFloat sizePixel = presContext->AppUnitsToGfxUnits(size);
|
2011-04-23 09:13:09 +04:00
|
|
|
if ((decorations & NS_FONT_DECORATION_UNDERLINE) &&
|
|
|
|
underStyle != NS_STYLE_TEXT_DECORATION_STYLE_NONE) {
|
2012-07-04 09:59:50 +04:00
|
|
|
nsCSSRendering::PaintDecorationLine(this, ctx, dirtyRect, underColor,
|
|
|
|
pt, xInFrame, gfxSize(width, sizePixel),
|
2009-04-03 11:26:28 +04:00
|
|
|
ascentPixel, offsetPixel,
|
2011-04-23 09:16:41 +04:00
|
|
|
NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE, underStyle);
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2011-04-23 09:13:09 +04:00
|
|
|
if ((decorations & NS_FONT_DECORATION_OVERLINE) &&
|
|
|
|
overStyle != NS_STYLE_TEXT_DECORATION_STYLE_NONE) {
|
2012-07-04 09:59:50 +04:00
|
|
|
nsCSSRendering::PaintDecorationLine(this, ctx, dirtyRect, overColor,
|
|
|
|
pt, xInFrame, gfxSize(width, sizePixel),
|
2009-04-03 11:26:28 +04:00
|
|
|
ascentPixel, ascentPixel,
|
2011-04-23 09:16:41 +04:00
|
|
|
NS_STYLE_TEXT_DECORATION_LINE_OVERLINE, overStyle);
|
2008-10-01 09:46:18 +04:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2007-08-07 23:07:43 +04:00
|
|
|
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRefPtr<nsRenderingContext> refContext =
|
2011-01-16 23:23:33 +03:00
|
|
|
PresContext()->PresShell()->GetReferenceRenderingContext();
|
|
|
|
|
2007-08-07 23:07:43 +04:00
|
|
|
aRenderingContext.SetFont(fontMet);
|
2011-01-16 23:23:33 +03:00
|
|
|
refContext->SetFont(fontMet);
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2011-01-16 23:23:33 +03:00
|
|
|
CalculateUnderline(*refContext);
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
aRenderingContext.SetColor(aOverrideColor ? *aOverrideColor : StyleColor()->mColor);
|
2000-10-08 09:56:55 +04:00
|
|
|
|
2001-05-15 15:58:40 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
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,
|
|
|
|
*refContext,
|
|
|
|
aTextRect.x, baseline,
|
|
|
|
&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,
|
|
|
|
*refContext,
|
|
|
|
aTextRect.x, baseline);
|
2001-11-12 23:51:48 +03:00
|
|
|
}
|
|
|
|
}
|
2001-05-15 15:58:40 +04:00
|
|
|
if (NS_FAILED(rv) )
|
|
|
|
#endif // IBMBIDI
|
2004-10-29 16:28:19 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
aRenderingContext.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)
|
2011-04-08 05:04:40 +04:00
|
|
|
mAccessKeyInfo->mBeforeWidth =
|
|
|
|
refContext->GetWidth(mCroppedTitle.get(),
|
|
|
|
mAccessKeyInfo->mAccesskeyIndex);
|
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(),
|
|
|
|
aTextRect.x, baseline, &aRenderingContext,
|
|
|
|
refContext.get());
|
2004-10-29 16:28:19 +04:00
|
|
|
}
|
2000-10-08 09:56:55 +04:00
|
|
|
|
|
|
|
if (mAccessKeyInfo && mAccessKeyInfo->mAccesskeyIndex != kNotFound) {
|
2008-10-01 04:57:51 +04:00
|
|
|
aRenderingContext.FillRect(aTextRect.x + mAccessKeyInfo->mBeforeWidth,
|
|
|
|
aTextRect.y + mAccessKeyInfo->mAccessOffset,
|
2000-10-08 09:56:55 +04:00
|
|
|
mAccessKeyInfo->mAccessWidth,
|
|
|
|
mAccessKeyInfo->mAccessUnderlineSize);
|
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.
|
2011-04-23 09:13:09 +04:00
|
|
|
if ((decorations & NS_FONT_DECORATION_LINE_THROUGH) &&
|
|
|
|
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);
|
2012-07-04 09:59:50 +04:00
|
|
|
nsCSSRendering::PaintDecorationLine(this, ctx, dirtyRect, strikeColor,
|
|
|
|
pt, xInFrame, gfxSize(width, sizePixel), ascentPixel,
|
|
|
|
offsetPixel, NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH,
|
2011-04-23 09:16:41 +04:00
|
|
|
strikeStyle);
|
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
|
2011-04-08 05:04:40 +04:00
|
|
|
nsTextBoxFrame::CalculateUnderline(nsRenderingContext& aRenderingContext)
|
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();
|
2011-10-17 18:59:28 +04:00
|
|
|
aRenderingContext.SetTextRunRTL(false);
|
2011-04-08 05:04:40 +04:00
|
|
|
mAccessKeyInfo->mAccessWidth =
|
|
|
|
aRenderingContext.GetWidth(titleString[mAccessKeyInfo->
|
|
|
|
mAccesskeyIndex]);
|
2000-02-17 02:00:52 +03:00
|
|
|
|
|
|
|
nscoord offset, baseline;
|
2011-04-08 05:05:49 +04:00
|
|
|
nsFontMetrics* metrics = aRenderingContext.FontMetrics();
|
2000-02-17 02:00:52 +03:00
|
|
|
metrics->GetUnderline(offset, mAccessKeyInfo->mAccessUnderlineSize);
|
2011-04-08 08:18:43 +04:00
|
|
|
baseline = metrics->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
|
2004-08-01 03:15:21 +04:00
|
|
|
nsTextBoxFrame::CalculateTitleForWidth(nsPresContext* aPresContext,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext& aRenderingContext,
|
2000-10-08 09:56:55 +04:00
|
|
|
nscoord aWidth)
|
2000-02-17 02:00:52 +03:00
|
|
|
{
|
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
|
|
|
|
2011-08-14 21:08:04 +04:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
|
|
|
|
aRenderingContext.SetFont(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
|
2011-01-03 04:48:09 +03:00
|
|
|
nscoord titleWidth = nsLayoutUtils::GetStringWidth(this, &aRenderingContext,
|
|
|
|
mTitle.get(), mTitle.Length());
|
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 = mTitle;
|
2001-05-15 15:58:40 +04:00
|
|
|
#ifdef IBMBIDI
|
2008-03-12 10:56:38 +03:00
|
|
|
if (HasRTLChars(mTitle)) {
|
2001-05-15 15:58:40 +04:00
|
|
|
mState |= NS_FRAME_IS_BIDI;
|
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
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?).
|
2011-10-17 18:59:28 +04:00
|
|
|
aRenderingContext.SetTextRunRTL(false);
|
2011-04-08 05:04:40 +04:00
|
|
|
titleWidth = aRenderingContext.GetWidth(kEllipsis);
|
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
|
2011-04-08 05:04:40 +04:00
|
|
|
cwidth = aRenderingContext.GetWidth(ch);
|
2000-10-08 09:56:55 +04:00
|
|
|
if (twidth + cwidth > aWidth)
|
|
|
|
break;
|
|
|
|
|
|
|
|
twidth += cwidth;
|
2001-05-15 15:58:40 +04:00
|
|
|
#ifdef IBMBIDI
|
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;
|
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
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);
|
2011-04-08 05:04:40 +04:00
|
|
|
cwidth = aRenderingContext.GetWidth(ch);
|
2000-10-08 09:56:55 +04:00
|
|
|
if (twidth + cwidth > aWidth)
|
|
|
|
break;
|
|
|
|
|
|
|
|
twidth += cwidth;
|
2001-05-15 15:58:40 +04:00
|
|
|
#ifdef IBMBIDI
|
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;
|
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
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 =
|
|
|
|
nsLayoutUtils::GetStringWidth(this, &aRenderingContext,
|
|
|
|
mTitle.get(), mTitle.Length());
|
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;
|
2011-10-17 18:59:28 +04:00
|
|
|
aRenderingContext.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);
|
2011-04-08 05:04:40 +04:00
|
|
|
charWidth = aRenderingContext.GetWidth(ch);
|
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
|
|
|
|
2001-05-15 15:58:40 +04:00
|
|
|
#ifdef IBMBIDI
|
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;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// look at the next character on the right end
|
|
|
|
if (rightPos > leftPos) {
|
|
|
|
// haven't looked at this character yet
|
|
|
|
ch = mTitle.CharAt(rightPos);
|
2011-04-08 05:04:40 +04:00
|
|
|
charWidth = aRenderingContext.GetWidth(ch);
|
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
|
|
|
|
2001-05-15 15:58:40 +04:00
|
|
|
#ifdef IBMBIDI
|
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;
|
|
|
|
#endif
|
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
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
return nsLayoutUtils::GetStringWidth(this, &aRenderingContext,
|
|
|
|
mCroppedTitle.get(), mCroppedTitle.Length());
|
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
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
nsRefPtr<nsFontMetrics> fontMet;
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
|
|
|
|
nsBoundingMetrics metrics =
|
2012-04-30 04:34:09 +04:00
|
|
|
fontMet->GetInkBoundsForVisualOverflow(mCroppedTitle.get(),
|
|
|
|
mCroppedTitle.Length(),
|
2012-04-27 04:24:54 +04:00
|
|
|
aBoxLayoutState.GetRenderingContext());
|
|
|
|
|
|
|
|
textRect.x -= metrics.leftBearing;
|
|
|
|
textRect.width = metrics.width;
|
|
|
|
// In DrawText() we always draw with the baseline at MaxAscent() (relative to mTextDrawRect),
|
|
|
|
textRect.y += fontMet->MaxAscent() - metrics.ascent;
|
|
|
|
textRect.height = metrics.ascent + metrics.descent;
|
|
|
|
|
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
|
|
|
|
nsTextBoxFrame::MarkIntrinsicWidthsDirty()
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsRecalc = true;
|
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
|
|
|
nsTextBoxFrameSuper::MarkIntrinsicWidthsDirty();
|
2000-10-08 09:56:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-08 08:18:43 +04:00
|
|
|
nsTextBoxFrame::GetTextSize(nsPresContext* aPresContext,
|
|
|
|
nsRenderingContext& aRenderingContext,
|
|
|
|
const nsString& aString,
|
|
|
|
nsSize& aSize, nscoord& aAscent)
|
2000-10-08 09:56:55 +04:00
|
|
|
{
|
2011-04-08 05:05:49 +04:00
|
|
|
nsRefPtr<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();
|
2000-10-08 09:56:55 +04:00
|
|
|
aRenderingContext.SetFont(fontMet);
|
2007-01-23 05:58:55 +03:00
|
|
|
aSize.width =
|
2011-04-08 08:18:43 +04:00
|
|
|
nsLayoutUtils::GetStringWidth(this, &aRenderingContext,
|
|
|
|
aString.get(), aString.Length());
|
|
|
|
aAscent = fontMet->MaxAscent();
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTextBoxFrame::CalcTextSize(nsBoxLayoutState& aBoxLayoutState)
|
|
|
|
{
|
2000-10-08 09:56:55 +04:00
|
|
|
if (mNeedsRecalc)
|
|
|
|
{
|
|
|
|
nsSize size;
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext* presContext = aBoxLayoutState.PresContext();
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* rendContext = aBoxLayoutState.GetRenderingContext();
|
2000-10-08 09:56:55 +04:00
|
|
|
if (rendContext) {
|
|
|
|
GetTextSize(presContext, *rendContext,
|
|
|
|
mTitle, size, mAscent);
|
|
|
|
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
|
|
|
{
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRect textRect(nsPoint(0, 0), GetSize());
|
2008-10-21 11:43:58 +04:00
|
|
|
nsMargin borderPadding;
|
|
|
|
GetBorderAndPadding(borderPadding);
|
|
|
|
textRect.Deflate(borderPadding);
|
2011-01-03 04:48:09 +03:00
|
|
|
|
2008-10-01 04:57:51 +04:00
|
|
|
// determine (cropped) title and underline position
|
|
|
|
nsPresContext* presContext = PresContext();
|
2011-01-03 04:48:09 +03:00
|
|
|
// determine (cropped) title which fits in aRect.width and its width
|
|
|
|
nscoord titleWidth =
|
|
|
|
CalculateTitleForWidth(presContext, aRenderingContext, textRect.width);
|
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.
|
|
|
|
nscoord outerWidth = textRect.width;
|
2011-01-03 04:48:09 +03:00
|
|
|
textRect.width = 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 nsStyleVisibility* vis = StyleVisibility();
|
|
|
|
const nsStyleText* textStyle = StyleText();
|
2008-10-01 04:57:51 +04:00
|
|
|
|
|
|
|
if (textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_CENTER)
|
|
|
|
textRect.x += (outerWidth - textRect.width)/2;
|
2009-02-06 06:48:30 +03:00
|
|
|
else if (textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_RIGHT ||
|
|
|
|
(textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_DEFAULT &&
|
|
|
|
vis->mDirection == NS_STYLE_DIRECTION_RTL) ||
|
|
|
|
(textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_END &&
|
|
|
|
vis->mDirection == NS_STYLE_DIRECTION_LTR)) {
|
|
|
|
textRect.x += (outerWidth - textRect.width);
|
2008-10-01 04:57:51 +04:00
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
|
|
|
|
mTextDrawRect = textRect;
|
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
|
|
|
|
if (mCropType != CropNone)
|
|
|
|
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);
|
2007-02-22 21:05:14 +03:00
|
|
|
ascent += m.top;
|
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
|
2011-04-21 21:35:52 +04:00
|
|
|
nsEventStateManager *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
|
|
|
}
|