2013-11-18 07:24:16 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-09 08:14:36 -07:00
|
|
|
#include "nsTextBoxFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsPresContext.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsIContent.h"
|
2014-02-27 15:04:46 -08:00
|
|
|
#include "nsNameSpaceManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
#include "nsMenuBarListener.h"
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMXULLabelElement.h"
|
2014-03-31 21:09:23 -07:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsITheme.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsContentUtils.h"
|
2013-05-22 09:05:26 -07:00
|
|
|
#include "nsCxPusher.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsDisplayList.h"
|
2007-08-06 01:15:00 -07:00
|
|
|
#include "nsCSSRendering.h"
|
2007-08-10 00:06:13 -07:00
|
|
|
#include "nsIReflowCallback.h"
|
2010-06-08 22:28:14 -07:00
|
|
|
#include "nsBoxFrame.h"
|
2011-05-26 21:53:03 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-08-09 08:14:36 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
2012-07-10 21:03:55 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-28 20:06:16 -08:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsBidiUtils.h"
|
|
|
|
#include "nsBidiPresUtils.h"
|
|
|
|
|
2011-05-26 21:53:03 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsAccessKeyInfo
|
|
|
|
{
|
|
|
|
public:
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mAccesskeyIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord mBeforeWidth, mAccessWidth, mAccessUnderlineSize, mAccessOffset;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsTextBoxFrame::gAlwaysAppendAccessKey = false;
|
|
|
|
bool nsTextBoxFrame::gAccessKeyPrefInitialized = false;
|
|
|
|
bool nsTextBoxFrame::gInsertSeparatorBeforeAccessKey = false;
|
|
|
|
bool nsTextBoxFrame::gInsertSeparatorPrefInitialized = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewTextBoxFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsTextBoxFrame (aPresShell, aContext);
|
2009-09-12 09:49:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsTextBoxFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-28 20:06:16 -08:00
|
|
|
NS_QUERYFRAME_HEAD(nsTextBoxFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsTextBoxFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsTextBoxFrameSuper)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTextBoxFrame::AttributeChanged(int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aResize;
|
|
|
|
bool aRedraw;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
UpdateAttributes(aAttribute, aResize, aRedraw);
|
|
|
|
|
|
|
|
if (aResize) {
|
2007-03-30 14:11:41 -07:00
|
|
|
PresContext()->PresShell()->
|
2007-05-06 12:16:51 -07:00
|
|
|
FrameNeedsReflow(this, nsIPresShell::eStyleChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (aRedraw) {
|
2007-03-30 14:11:41 -07:00
|
|
|
nsBoxLayoutState state(PresContext());
|
2007-03-22 10:30:00 -07:00
|
|
|
Redraw(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the accesskey changed, register for the new value
|
|
|
|
// The old value has been unregistered in nsXULElement::SetAttr
|
|
|
|
if (aAttribute == nsGkAtoms::accesskey || aAttribute == nsGkAtoms::control)
|
2011-10-17 07:59:28 -07:00
|
|
|
RegUnregAccessKey(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTextBoxFrame::nsTextBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext):
|
2012-07-30 07:20:58 -07:00
|
|
|
nsLeafBoxFrame(aShell, aContext), mAccessKeyInfo(nullptr), mCropType(CropRight),
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsReflowCallback(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
MarkIntrinsicWidthsDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTextBoxFrame::~nsTextBoxFrame()
|
|
|
|
{
|
|
|
|
delete mAccessKeyInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTextBoxFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsTextBoxFrameSuper::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aResize;
|
|
|
|
bool aRedraw;
|
2012-07-30 07:20:58 -07:00
|
|
|
UpdateAttributes(nullptr, aResize, aRedraw); /* update all */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// register access key
|
2011-10-17 07:59:28 -07:00
|
|
|
RegUnregAccessKey(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsTextBoxFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// unregister access key
|
2011-10-17 07:59:28 -07:00
|
|
|
RegUnregAccessKey(false);
|
2009-12-23 21:21:15 -08:00
|
|
|
nsTextBoxFrameSuper::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTextBoxFrame::AlwaysAppendAccessKey()
|
|
|
|
{
|
|
|
|
if (!gAccessKeyPrefInitialized)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
gAccessKeyPrefInitialized = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
const char* prefName = "intl.menuitems.alwaysappendaccesskeys";
|
2011-05-26 21:53:03 -07:00
|
|
|
nsAdoptingString val = Preferences::GetLocalizedString(prefName);
|
2007-03-22 10:30:00 -07:00
|
|
|
gAlwaysAppendAccessKey = val.Equals(NS_LITERAL_STRING("true"));
|
|
|
|
}
|
|
|
|
return gAlwaysAppendAccessKey;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTextBoxFrame::InsertSeparatorBeforeAccessKey()
|
|
|
|
{
|
|
|
|
if (!gInsertSeparatorPrefInitialized)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
gInsertSeparatorPrefInitialized = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
const char* prefName = "intl.menuitems.insertseparatorbeforeaccesskeys";
|
2011-05-26 21:53:03 -07:00
|
|
|
nsAdoptingString val = Preferences::GetLocalizedString(prefName);
|
2007-03-22 10:30:00 -07:00
|
|
|
gInsertSeparatorBeforeAccessKey = val.EqualsLiteral("true");
|
|
|
|
}
|
|
|
|
return gInsertSeparatorBeforeAccessKey;
|
|
|
|
}
|
|
|
|
|
2012-07-10 21:03:55 -07:00
|
|
|
class nsAsyncAccesskeyUpdate MOZ_FINAL : public nsIReflowCallback
|
2007-08-10 00:06:13 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsAsyncAccesskeyUpdate(nsIFrame* aFrame) : mWeakFrame(aFrame)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual bool ReflowFinished() MOZ_OVERRIDE
|
2007-08-10 00:06:13 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool shouldFlush = false;
|
2007-08-10 00:06:13 -07:00
|
|
|
nsTextBoxFrame* frame =
|
|
|
|
static_cast<nsTextBoxFrame*>(mWeakFrame.GetFrame());
|
|
|
|
if (frame) {
|
|
|
|
shouldFlush = frame->UpdateAccesskey(mWeakFrame);
|
|
|
|
}
|
|
|
|
delete this;
|
|
|
|
return shouldFlush;
|
|
|
|
}
|
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual void ReflowCallbackCanceled() MOZ_OVERRIDE
|
2007-11-30 23:22:44 -08:00
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2007-08-10 00:06:13 -07:00
|
|
|
nsWeakFrame mWeakFrame;
|
|
|
|
};
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-08-10 00:06:13 -07:00
|
|
|
nsTextBoxFrame::UpdateAccesskey(nsWeakFrame& aWeakThis)
|
|
|
|
{
|
|
|
|
nsAutoString accesskey;
|
|
|
|
nsCOMPtr<nsIDOMXULLabelElement> labelElement = do_QueryInterface(mContent);
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(aWeakThis.IsAlive(), false);
|
2007-08-10 00:06:13 -07:00
|
|
|
if (labelElement) {
|
|
|
|
// Accesskey may be stored on control.
|
2007-08-17 17:13:14 -07: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 03:02:32 -07:00
|
|
|
nsCxPusher cx;
|
|
|
|
if (cx.Push(mContent)) {
|
|
|
|
labelElement->GetAccessKey(accesskey);
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(aWeakThis.IsAlive(), false);
|
2007-10-01 03:02:32 -07:00
|
|
|
}
|
2007-08-10 00:06:13 -07: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 07:59:28 -07:00
|
|
|
return true;
|
2007-08-10 00:06:13 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-08-10 00:06:13 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsTextBoxFrame::UpdateAttributes(nsIAtom* aAttribute,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool& aResize,
|
|
|
|
bool& aRedraw)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool doUpdateTitle = false;
|
2011-10-17 07:59:28 -07:00
|
|
|
aResize = false;
|
|
|
|
aRedraw = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
if (aAttribute == nullptr || aAttribute == nsGkAtoms::crop) {
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
|
|
|
{&nsGkAtoms::left, &nsGkAtoms::start, &nsGkAtoms::center,
|
2012-07-30 07:20:58 -07:00
|
|
|
&nsGkAtoms::right, &nsGkAtoms::end, nullptr};
|
2007-03-22 10:30:00 -07:00
|
|
|
CroppingStyle cropType;
|
|
|
|
switch (mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::crop,
|
|
|
|
strings, eCaseMatters)) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
cropType = CropLeft;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
cropType = CropCenter;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
cropType = CropRight;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cropType = CropNone;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cropType != mCropType) {
|
2011-10-17 07:59:28 -07:00
|
|
|
aResize = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
mCropType = cropType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
if (aAttribute == nullptr || aAttribute == nsGkAtoms::value) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, mTitle);
|
2011-10-17 07:59:28 -07:00
|
|
|
doUpdateTitle = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
if (aAttribute == nullptr || aAttribute == nsGkAtoms::accesskey) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsReflowCallback = true;
|
2007-08-10 00:06:13 -07:00
|
|
|
// Ensure that layout is refreshed and reflow callback called.
|
2011-10-17 07:59:28 -07:00
|
|
|
aResize = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (doUpdateTitle) {
|
|
|
|
UpdateAccessTitle();
|
2011-10-17 07:59:28 -07:00
|
|
|
aResize = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class nsDisplayXULTextBox : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayXULTextBox(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsTextBoxFrame* aFrame) :
|
2011-01-02 17:48:09 -08:00
|
|
|
nsDisplayItem(aBuilder, aFrame),
|
2011-10-17 07:59:28 -07:00
|
|
|
mDisableSubpixelAA(false)
|
2011-01-02 17:48:09 -08:00
|
|
|
{
|
2010-08-13 03:01:13 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayXULTextBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayXULTextBox() {
|
2010-08-13 03:01:13 -07:00
|
|
|
MOZ_COUNT_DTOR(nsDisplayXULTextBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-06 17:35:14 -07:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2014-02-24 06:41:56 -08:00
|
|
|
nsRenderingContext* aCtx) MOZ_OVERRIDE;
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
|
|
|
|
bool* aSnap) MOZ_OVERRIDE;
|
2010-07-15 14:07:49 -07:00
|
|
|
NS_DISPLAY_DECL_NAME("XULTextBox", TYPE_XUL_TEXT_BOX)
|
2010-10-10 17:58:20 -07:00
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual nsRect GetComponentAlphaBounds(nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE;
|
2011-01-02 17:48:09 -08:00
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual void DisableComponentAlpha() MOZ_OVERRIDE {
|
|
|
|
mDisableSubpixelAA = true;
|
|
|
|
}
|
2011-01-02 17:48:09 -08:00
|
|
|
|
2011-07-03 21:59:19 -07:00
|
|
|
void PaintTextToContext(nsRenderingContext* aCtx,
|
|
|
|
nsPoint aOffset,
|
|
|
|
const nscolor* aColor);
|
2011-06-30 23:43:11 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mDisableSubpixelAA;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2011-06-30 23:43:11 -07:00
|
|
|
static void
|
|
|
|
PaintTextShadowCallback(nsRenderingContext* aCtx,
|
|
|
|
nsPoint aShadowOffset,
|
|
|
|
const nscolor& aShadowColor,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
reinterpret_cast<nsDisplayXULTextBox*>(aData)->
|
2011-07-03 21:59:19 -07:00
|
|
|
PaintTextToContext(aCtx, aShadowOffset, &aShadowColor);
|
2011-06-30 23:43:11 -07:00
|
|
|
}
|
|
|
|
|
2008-11-25 14:59:06 -08:00
|
|
|
void
|
|
|
|
nsDisplayXULTextBox::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-01-02 17:48:09 -08:00
|
|
|
gfxContextAutoDisableSubpixelAntialiasing disable(aCtx->ThebesContext(),
|
|
|
|
mDisableSubpixelAA);
|
2011-06-30 23:43:11 -07:00
|
|
|
|
|
|
|
// Paint the text shadow before doing any foreground stuff
|
2011-07-03 21:59:19 -07:00
|
|
|
nsRect drawRect = static_cast<nsTextBoxFrame*>(mFrame)->mTextDrawRect +
|
|
|
|
ToReferenceFrame();
|
2011-06-30 23:43:11 -07:00
|
|
|
nsLayoutUtils::PaintTextShadow(mFrame, aCtx,
|
|
|
|
drawRect, mVisibleRect,
|
2013-02-16 13:51:02 -08:00
|
|
|
mFrame->StyleColor()->mColor,
|
2011-06-30 23:43:11 -07:00
|
|
|
PaintTextShadowCallback,
|
|
|
|
(void*)this);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
PaintTextToContext(aCtx, nsPoint(0, 0), nullptr);
|
2011-06-30 23:43:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-07-03 21:59:19 -07:00
|
|
|
nsDisplayXULTextBox::PaintTextToContext(nsRenderingContext* aCtx,
|
|
|
|
nsPoint aOffset,
|
|
|
|
const nscolor* aColor)
|
2011-06-30 23:43:11 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsTextBoxFrame*>(mFrame)->
|
2011-07-01 01:21:46 -07:00
|
|
|
PaintTitle(*aCtx, mVisibleRect, ToReferenceFrame() + aOffset, aColor);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-11-25 14:59:06 -08:00
|
|
|
nsRect
|
2012-04-10 04:24:18 -07:00
|
|
|
nsDisplayXULTextBox::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) {
|
|
|
|
*aSnap = false;
|
2011-10-21 10:45:32 -07:00
|
|
|
return mFrame->GetVisualOverflowRectRelativeToSelf() + ToReferenceFrame();
|
2008-11-25 14:59:06 -08:00
|
|
|
}
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRect
|
|
|
|
nsDisplayXULTextBox::GetComponentAlphaBounds(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
return static_cast<nsTextBoxFrame*>(mFrame)->GetComponentAlphaBounds() +
|
|
|
|
ToReferenceFrame();
|
|
|
|
}
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTextBoxFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
if (!IsVisibleForPainting(aBuilder))
|
2013-02-14 03:12:27 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-14 03:08:08 -08:00
|
|
|
nsLeafBoxFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-14 03:08:08 -08:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
2013-02-14 03:12:27 -08:00
|
|
|
nsDisplayXULTextBox(aBuilder, this));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-07 18:04:40 -07:00
|
|
|
nsTextBoxFrame::PaintTitle(nsRenderingContext& aRenderingContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsRect& aDirtyRect,
|
2011-07-01 01:21:46 -07:00
|
|
|
nsPoint aPt,
|
|
|
|
const nscolor* aOverrideColor)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mTitle.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
2011-09-16 12:23:29 -07:00
|
|
|
DrawText(aRenderingContext, aDirtyRect, mTextDrawRect + aPt, aOverrideColor);
|
2008-09-30 17:57:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-07 18:04:40 -07:00
|
|
|
nsTextBoxFrame::DrawText(nsRenderingContext& aRenderingContext,
|
2011-09-16 12:23:29 -07:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aTextRect,
|
|
|
|
const nscolor* aOverrideColor)
|
2008-09-30 17:57:51 -07:00
|
|
|
{
|
|
|
|
nsPresContext* presContext = PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// paint the title
|
|
|
|
nscolor overColor;
|
|
|
|
nscolor underColor;
|
|
|
|
nscolor strikeColor;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t overStyle;
|
|
|
|
uint8_t underStyle;
|
|
|
|
uint8_t strikeStyle;
|
2011-04-22 22:16:41 -07:00
|
|
|
|
|
|
|
// Begin with no decorations
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t decorations = NS_STYLE_TEXT_DECORATION_LINE_NONE;
|
2011-04-22 22:16:41 -07:00
|
|
|
// A mask of all possible decorations.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t decorMask = NS_STYLE_TEXT_DECORATION_LINE_LINES_MASK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-09 08:14:36 -07:00
|
|
|
nsIFrame* f = this;
|
2007-03-22 10:30:00 -07:00
|
|
|
do { // find decoration colors
|
2013-02-15 21:38:33 -08:00
|
|
|
nsStyleContext* context = f->StyleContext();
|
2011-08-09 08:14:36 -07:00
|
|
|
if (!context->HasTextDecorationLines()) {
|
|
|
|
break;
|
|
|
|
}
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleTextReset* styleText = context->StyleTextReset();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-22 22:16:41 -07:00
|
|
|
if (decorMask & styleText->mTextDecorationLine) { // a decoration defined here
|
2011-03-31 05:27:03 -07:00
|
|
|
nscolor color;
|
|
|
|
if (aOverrideColor) {
|
|
|
|
color = *aOverrideColor;
|
|
|
|
} else {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isForeground;
|
2011-03-31 05:27:03 -07:00
|
|
|
styleText->GetDecorationColor(color, isForeground);
|
|
|
|
if (isForeground) {
|
2011-08-09 08:14:36 -07:00
|
|
|
color = nsLayoutUtils::GetColor(f, eCSSProperty_color);
|
2011-03-31 05:27:03 -07:00
|
|
|
}
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t style = styleText->GetDecorationStyle();
|
2011-03-31 05:27:03 -07:00
|
|
|
|
2011-04-22 22:16:41 -07:00
|
|
|
if (NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE & decorMask &
|
|
|
|
styleText->mTextDecorationLine) {
|
2007-03-22 10:30:00 -07:00
|
|
|
underColor = color;
|
2011-03-31 05:27:03 -07:00
|
|
|
underStyle = style;
|
2011-04-22 22:16:41 -07:00
|
|
|
decorMask &= ~NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE;
|
|
|
|
decorations |= NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-04-22 22:16:41 -07:00
|
|
|
if (NS_STYLE_TEXT_DECORATION_LINE_OVERLINE & decorMask &
|
|
|
|
styleText->mTextDecorationLine) {
|
2007-03-22 10:30:00 -07:00
|
|
|
overColor = color;
|
2011-03-31 05:27:03 -07:00
|
|
|
overStyle = style;
|
2011-04-22 22:16:41 -07:00
|
|
|
decorMask &= ~NS_STYLE_TEXT_DECORATION_LINE_OVERLINE;
|
|
|
|
decorations |= NS_STYLE_TEXT_DECORATION_LINE_OVERLINE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-04-22 22:16:41 -07:00
|
|
|
if (NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH & decorMask &
|
|
|
|
styleText->mTextDecorationLine) {
|
2007-03-22 10:30:00 -07:00
|
|
|
strikeColor = color;
|
2011-03-31 05:27:03 -07:00
|
|
|
strikeStyle = style;
|
2011-04-22 22:16:41 -07:00
|
|
|
decorMask &= ~NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH;
|
|
|
|
decorations |= NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2011-08-09 08:14:36 -07:00
|
|
|
} while (0 != decorMask &&
|
2012-06-10 16:44:50 -07:00
|
|
|
(f = nsLayoutUtils::GetParentOrPlaceholderFor(f)));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-07 18:05:49 -07:00
|
|
|
nsRefPtr<nsFontMetrics> fontMet;
|
2007-08-07 12:07:43 -07:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord offset;
|
|
|
|
nscoord size;
|
2011-04-07 21:18:43 -07:00
|
|
|
nscoord ascent = fontMet->MaxAscent();
|
2007-08-06 01:15:00 -07:00
|
|
|
|
2007-09-03 08:27:26 -07:00
|
|
|
nscoord baseline =
|
2008-09-30 17:57:51 -07:00
|
|
|
presContext->RoundAppUnitsToNearestDevPixels(aTextRect.y + ascent);
|
2007-12-18 15:01:15 -08:00
|
|
|
nsRefPtr<gfxContext> ctx = aRenderingContext.ThebesContext();
|
2008-09-30 17:57:51 -07:00
|
|
|
gfxPoint pt(presContext->AppUnitsToGfxUnits(aTextRect.x),
|
|
|
|
presContext->AppUnitsToGfxUnits(aTextRect.y));
|
|
|
|
gfxFloat width = presContext->AppUnitsToGfxUnits(aTextRect.width);
|
2007-09-03 08:27:26 -07:00
|
|
|
gfxFloat ascentPixel = presContext->AppUnitsToGfxUnits(ascent);
|
2012-07-03 22:59:50 -07:00
|
|
|
gfxFloat xInFrame = PresContext()->AppUnitsToGfxUnits(mTextDrawRect.x);
|
2011-09-16 12:23:29 -07:00
|
|
|
gfxRect dirtyRect(presContext->AppUnitsToGfxUnits(aDirtyRect));
|
2008-09-30 22:46:18 -07: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)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
fontMet->GetUnderline(offset, size);
|
2007-08-22 04:13:46 -07:00
|
|
|
gfxFloat offsetPixel = presContext->AppUnitsToGfxUnits(offset);
|
|
|
|
gfxFloat sizePixel = presContext->AppUnitsToGfxUnits(size);
|
2011-04-22 22:13:09 -07:00
|
|
|
if ((decorations & NS_FONT_DECORATION_UNDERLINE) &&
|
|
|
|
underStyle != NS_STYLE_TEXT_DECORATION_STYLE_NONE) {
|
2012-07-03 22:59:50 -07:00
|
|
|
nsCSSRendering::PaintDecorationLine(this, ctx, dirtyRect, underColor,
|
|
|
|
pt, xInFrame, gfxSize(width, sizePixel),
|
2009-04-03 00:26:28 -07:00
|
|
|
ascentPixel, offsetPixel,
|
2011-04-22 22:16:41 -07:00
|
|
|
NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE, underStyle);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-04-22 22:13:09 -07:00
|
|
|
if ((decorations & NS_FONT_DECORATION_OVERLINE) &&
|
|
|
|
overStyle != NS_STYLE_TEXT_DECORATION_STYLE_NONE) {
|
2012-07-03 22:59:50 -07:00
|
|
|
nsCSSRendering::PaintDecorationLine(this, ctx, dirtyRect, overColor,
|
|
|
|
pt, xInFrame, gfxSize(width, sizePixel),
|
2009-04-03 00:26:28 -07:00
|
|
|
ascentPixel, ascentPixel,
|
2011-04-22 22:16:41 -07:00
|
|
|
NS_STYLE_TEXT_DECORATION_LINE_OVERLINE, overStyle);
|
2008-09-30 22:46:18 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-08-07 12:07:43 -07:00
|
|
|
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRefPtr<nsRenderingContext> refContext =
|
2014-04-14 21:30:25 -07:00
|
|
|
PresContext()->PresShell()->CreateReferenceRenderingContext();
|
2011-01-16 12:23:33 -08:00
|
|
|
|
2007-08-07 12:07:43 -07:00
|
|
|
aRenderingContext.SetFont(fontMet);
|
2011-01-16 12:23:33 -08:00
|
|
|
refContext->SetFont(fontMet);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-01-16 12:23:33 -08:00
|
|
|
CalculateUnderline(*refContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
aRenderingContext.SetColor(aOverrideColor ? *aOverrideColor : StyleColor()->mColor);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (mState & NS_FRAME_IS_BIDI) {
|
2008-06-16 02:28:17 -07:00
|
|
|
presContext->SetBidiEnabled();
|
2013-11-18 07:24:16 -08:00
|
|
|
nsBidiLevel level = nsBidiPresUtils::BidiLevelFromStyle(StyleContext());
|
2011-04-13 02:23:49 -07: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 07:24:16 -08:00
|
|
|
rv = nsBidiPresUtils::RenderText(mCroppedTitle.get(), mCroppedTitle.Length(), level,
|
2011-04-13 02:23:49 -07:00
|
|
|
presContext, aRenderingContext,
|
|
|
|
*refContext,
|
|
|
|
aTextRect.x, baseline,
|
|
|
|
&posResolve,
|
|
|
|
1);
|
|
|
|
mAccessKeyInfo->mBeforeWidth = posResolve.visualLeftTwips;
|
|
|
|
mAccessKeyInfo->mAccessWidth = posResolve.visualWidth;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-18 07:24:16 -08:00
|
|
|
rv = nsBidiPresUtils::RenderText(mCroppedTitle.get(), mCroppedTitle.Length(), level,
|
2011-04-13 02:23:49 -07:00
|
|
|
presContext, aRenderingContext,
|
|
|
|
*refContext,
|
|
|
|
aTextRect.x, baseline);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2014-04-23 18:15:29 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
aRenderingContext.SetTextRunRTL(false);
|
2007-03-22 10:30:00 -07: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-07 18:04:40 -07:00
|
|
|
mAccessKeyInfo->mBeforeWidth =
|
|
|
|
refContext->GetWidth(mCroppedTitle.get(),
|
|
|
|
mAccessKeyInfo->mAccesskeyIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
|
|
|
mAccessKeyInfo->mBeforeWidth = 0;
|
|
|
|
}
|
|
|
|
|
2011-04-07 18:05:25 -07:00
|
|
|
fontMet->DrawString(mCroppedTitle.get(), mCroppedTitle.Length(),
|
|
|
|
aTextRect.x, baseline, &aRenderingContext,
|
|
|
|
refContext.get());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mAccessKeyInfo && mAccessKeyInfo->mAccesskeyIndex != kNotFound) {
|
2008-09-30 17:57:51 -07:00
|
|
|
aRenderingContext.FillRect(aTextRect.x + mAccessKeyInfo->mBeforeWidth,
|
|
|
|
aTextRect.y + mAccessKeyInfo->mAccessOffset,
|
2007-03-22 10:30:00 -07:00
|
|
|
mAccessKeyInfo->mAccessWidth,
|
|
|
|
mAccessKeyInfo->mAccessUnderlineSize);
|
|
|
|
}
|
2008-09-30 22:46:18 -07: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-22 22:13:09 -07:00
|
|
|
if ((decorations & NS_FONT_DECORATION_LINE_THROUGH) &&
|
|
|
|
strikeStyle != NS_STYLE_TEXT_DECORATION_STYLE_NONE) {
|
2008-09-30 22:46:18 -07:00
|
|
|
fontMet->GetStrikeout(offset, size);
|
|
|
|
gfxFloat offsetPixel = presContext->AppUnitsToGfxUnits(offset);
|
|
|
|
gfxFloat sizePixel = presContext->AppUnitsToGfxUnits(size);
|
2012-07-03 22:59:50 -07:00
|
|
|
nsCSSRendering::PaintDecorationLine(this, ctx, dirtyRect, strikeColor,
|
|
|
|
pt, xInFrame, gfxSize(width, sizePixel), ascentPixel,
|
|
|
|
offsetPixel, NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH,
|
2011-04-22 22:16:41 -07:00
|
|
|
strikeStyle);
|
2008-09-30 22:46:18 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-07 18:04:40 -07:00
|
|
|
nsTextBoxFrame::CalculateUnderline(nsRenderingContext& aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mAccessKeyInfo && mAccessKeyInfo->mAccesskeyIndex != kNotFound) {
|
|
|
|
// Calculate all fields of mAccessKeyInfo which
|
|
|
|
// are the same for both BiDi and non-BiDi frames.
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t *titleString = mCroppedTitle.get();
|
2011-10-17 07:59:28 -07:00
|
|
|
aRenderingContext.SetTextRunRTL(false);
|
2011-04-07 18:04:40 -07:00
|
|
|
mAccessKeyInfo->mAccessWidth =
|
|
|
|
aRenderingContext.GetWidth(titleString[mAccessKeyInfo->
|
|
|
|
mAccesskeyIndex]);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nscoord offset, baseline;
|
2011-04-07 18:05:49 -07:00
|
|
|
nsFontMetrics* metrics = aRenderingContext.FontMetrics();
|
2007-03-22 10:30:00 -07:00
|
|
|
metrics->GetUnderline(offset, mAccessKeyInfo->mAccessUnderlineSize);
|
2011-04-07 21:18:43 -07:00
|
|
|
baseline = metrics->MaxAscent();
|
2007-03-22 10:30:00 -07:00
|
|
|
mAccessKeyInfo->mAccessOffset = baseline - offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
nscoord
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTextBoxFrame::CalculateTitleForWidth(nsPresContext* aPresContext,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext& aRenderingContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord aWidth)
|
|
|
|
{
|
2013-02-28 20:06:16 -08:00
|
|
|
if (mTitle.IsEmpty()) {
|
|
|
|
mCroppedTitle.Truncate();
|
2011-01-02 17:48:09 -08:00
|
|
|
return 0;
|
2013-02-28 20:06:16 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-14 10:08:04 -07:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
|
|
|
|
aRenderingContext.SetFont(fm);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// see if the text will completely fit in the width given
|
2011-01-02 17:48:09 -08:00
|
|
|
nscoord titleWidth = nsLayoutUtils::GetStringWidth(this, &aRenderingContext,
|
|
|
|
mTitle.get(), mTitle.Length());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
if (titleWidth <= aWidth) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mCroppedTitle = mTitle;
|
2008-03-12 00:56:38 -07:00
|
|
|
if (HasRTLChars(mTitle)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mState |= NS_FRAME_IS_BIDI;
|
|
|
|
}
|
2011-01-02 17:48:09 -08:00
|
|
|
return titleWidth; // fits, done.
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-01-26 15:00:19 -08:00
|
|
|
const nsDependentString& kEllipsis = nsContentUtils::GetLocalizedEllipsis();
|
2007-03-22 10:30:00 -07:00
|
|
|
// start with an ellipsis
|
2007-11-19 02:17:17 -08:00
|
|
|
mCroppedTitle.Assign(kEllipsis);
|
2007-03-22 10:30:00 -07: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 07:59:28 -07:00
|
|
|
aRenderingContext.SetTextRunRTL(false);
|
2011-04-07 18:04:40 -07:00
|
|
|
titleWidth = aRenderingContext.GetWidth(kEllipsis);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
if (titleWidth > aWidth) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mCroppedTitle.SetLength(0);
|
2011-01-02 17:48:09 -08:00
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// if the ellipsis fits perfectly, no use in trying to insert
|
2011-01-02 17:48:09 -08:00
|
|
|
if (titleWidth == aWidth)
|
|
|
|
return titleWidth;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
aWidth -= titleWidth;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// XXX: This whole block should probably take surrogates into account
|
|
|
|
// XXX and clusters!
|
|
|
|
// ok crop things
|
|
|
|
switch (mCropType)
|
|
|
|
{
|
|
|
|
case CropNone:
|
|
|
|
case CropRight:
|
|
|
|
{
|
|
|
|
nscoord cwidth;
|
|
|
|
nscoord twidth = 0;
|
|
|
|
int length = mTitle.Length();
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < length; ++i) {
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t ch = mTitle.CharAt(i);
|
2007-03-22 10:30:00 -07:00
|
|
|
// still in LTR mode
|
2011-04-07 18:04:40 -07:00
|
|
|
cwidth = aRenderingContext.GetWidth(ch);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (twidth + cwidth > aWidth)
|
|
|
|
break;
|
|
|
|
|
|
|
|
twidth += cwidth;
|
|
|
|
if (UCS2_CHAR_IS_BIDI(ch) ) {
|
|
|
|
mState |= NS_FRAME_IS_BIDI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0)
|
2011-01-02 17:48:09 -08:00
|
|
|
return titleWidth;
|
2007-03-22 10:30:00 -07: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 07:02:17 -08:00
|
|
|
char16_t ch = mTitle.CharAt(i);
|
2011-04-07 18:04:40 -07:00
|
|
|
cwidth = aRenderingContext.GetWidth(ch);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (twidth + cwidth > aWidth)
|
|
|
|
break;
|
|
|
|
|
|
|
|
twidth += cwidth;
|
|
|
|
if (UCS2_CHAR_IS_BIDI(ch) ) {
|
|
|
|
mState |= NS_FRAME_IS_BIDI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == length-1)
|
2011-01-02 17:48:09 -08:00
|
|
|
return titleWidth;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString copy;
|
|
|
|
mTitle.Right(copy, length-1-i);
|
|
|
|
mCroppedTitle += copy;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CropCenter:
|
|
|
|
{
|
|
|
|
nscoord stringWidth =
|
|
|
|
nsLayoutUtils::GetStringWidth(this, &aRenderingContext,
|
|
|
|
mTitle.get(), mTitle.Length());
|
|
|
|
if (stringWidth <= aWidth) {
|
|
|
|
// the entire string will fit in the maximum width
|
|
|
|
mCroppedTitle.Insert(mTitle, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// determine how much of the string will fit in the max width
|
|
|
|
nscoord charWidth = 0;
|
|
|
|
nscoord totalWidth = 0;
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t ch;
|
2007-03-22 10:30:00 -07:00
|
|
|
int leftPos, rightPos;
|
|
|
|
nsAutoString leftString, rightString;
|
|
|
|
|
|
|
|
rightPos = mTitle.Length() - 1;
|
2011-10-17 07:59:28 -07:00
|
|
|
aRenderingContext.SetTextRunRTL(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
for (leftPos = 0; leftPos <= rightPos;) {
|
|
|
|
// look at the next character on the left end
|
|
|
|
ch = mTitle.CharAt(leftPos);
|
2011-04-07 18:04:40 -07:00
|
|
|
charWidth = aRenderingContext.GetWidth(ch);
|
2007-03-22 10:30:00 -07:00
|
|
|
totalWidth += charWidth;
|
|
|
|
if (totalWidth > aWidth)
|
|
|
|
// greater than the allowable width
|
|
|
|
break;
|
|
|
|
leftString.Insert(ch, leftString.Length());
|
|
|
|
|
|
|
|
if (UCS2_CHAR_IS_BIDI(ch))
|
|
|
|
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);
|
2011-04-07 18:04:40 -07:00
|
|
|
charWidth = aRenderingContext.GetWidth(ch);
|
2007-03-22 10:30:00 -07:00
|
|
|
totalWidth += charWidth;
|
|
|
|
if (totalWidth > aWidth)
|
|
|
|
// greater than the allowable width
|
|
|
|
break;
|
|
|
|
rightString.Insert(ch, 0);
|
|
|
|
|
|
|
|
if (UCS2_CHAR_IS_BIDI(ch))
|
|
|
|
mState |= NS_FRAME_IS_BIDI;
|
|
|
|
}
|
|
|
|
|
|
|
|
// look at the next two characters
|
|
|
|
leftPos++;
|
|
|
|
rightPos--;
|
|
|
|
}
|
|
|
|
|
2007-11-19 02:17:17 -08:00
|
|
|
mCroppedTitle = leftString + kEllipsis + rightString;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
return nsLayoutUtils::GetStringWidth(this, &aRenderingContext,
|
|
|
|
mCroppedTitle.get(), mCroppedTitle.Length());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-11-19 02:17:17 -08:00
|
|
|
#define OLD_ELLIPSIS NS_LITERAL_STRING("...")
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// the following block is to append the accesskey to mTitle if there is an accesskey
|
|
|
|
// but the mTitle doesn't have the character
|
|
|
|
void
|
|
|
|
nsTextBoxFrame::UpdateAccessTitle()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 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 08:56:38 -07:00
|
|
|
int32_t menuAccessKey;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuBarListener::GetMenuAccessKey(&menuAccessKey);
|
|
|
|
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-26 15:00:19 -08:00
|
|
|
const nsDependentString& kEllipsis = nsContentUtils::GetLocalizedEllipsis();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t offset = mTitle.Length();
|
2007-12-12 21:51:40 -08:00
|
|
|
if (StringEndsWith(mTitle, kEllipsis)) {
|
|
|
|
offset -= kEllipsis.Length();
|
|
|
|
} else if (StringEndsWith(mTitle, OLD_ELLIPSIS)) {
|
2007-11-19 02:17:17 -08:00
|
|
|
// Try to check with our old ellipsis (for old addons)
|
2007-12-12 21:51:40 -08:00
|
|
|
offset -= OLD_ELLIPSIS.Length();
|
|
|
|
} else {
|
|
|
|
// Try to check with
|
|
|
|
// our default ellipsis (for non-localized addons) or ':'
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t kLastChar = mTitle.Last();
|
|
|
|
if (kLastChar == char16_t(0x2026) || kLastChar == char16_t(':'))
|
2007-03-22 10:30:00 -07:00
|
|
|
offset--;
|
|
|
|
}
|
|
|
|
|
2007-12-12 21:51:40 -08:00
|
|
|
if (InsertSeparatorBeforeAccessKey() &&
|
2010-05-11 17:30:42 -07:00
|
|
|
offset > 0 && !NS_IS_SPACE(mTitle[offset - 1])) {
|
2007-12-12 21:51:40 -08:00
|
|
|
mTitle.Insert(' ', offset);
|
2007-03-22 10:30:00 -07:00
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
|
2007-12-12 21:51:40 -08:00
|
|
|
mTitle.Insert(accessKeyLabel, offset);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTextBoxFrame::UpdateAccessIndex()
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t menuAccessKey;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuBarListener::GetMenuAccessKey(&menuAccessKey);
|
|
|
|
if (menuAccessKey) {
|
|
|
|
if (mAccessKey.IsEmpty()) {
|
|
|
|
if (mAccessKeyInfo) {
|
|
|
|
delete mAccessKeyInfo;
|
2012-07-30 07:20:58 -07:00
|
|
|
mAccessKeyInfo = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!mAccessKeyInfo) {
|
|
|
|
mAccessKeyInfo = new nsAccessKeyInfo();
|
|
|
|
if (!mAccessKeyInfo)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAString::const_iterator start, end;
|
|
|
|
|
|
|
|
mCroppedTitle.BeginReading(start);
|
|
|
|
mCroppedTitle.EndReading(end);
|
|
|
|
|
|
|
|
// remember the beginning of the string
|
|
|
|
nsAString::const_iterator originalStart = start;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool found;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!AlwaysAppendAccessKey()) {
|
|
|
|
// not appending access key - do case-sensitive search
|
|
|
|
// first
|
|
|
|
found = FindInReadable(mAccessKey, start, end);
|
|
|
|
if (!found) {
|
|
|
|
// didn't find it - perform a case-insensitive search
|
|
|
|
start = originalStart;
|
|
|
|
found = FindInReadable(mAccessKey, start, end,
|
|
|
|
nsCaseInsensitiveStringComparator());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
found = RFindInReadable(mAccessKey, start, end,
|
|
|
|
nsCaseInsensitiveStringComparator());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
mAccessKeyInfo->mAccesskeyIndex = Distance(originalStart, start);
|
|
|
|
else
|
|
|
|
mAccessKeyInfo->mAccesskeyIndex = kNotFound;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextBoxFrame::DoLayout(nsBoxLayoutState& aBoxLayoutState)
|
|
|
|
{
|
2007-09-04 01:46:50 -07:00
|
|
|
if (mNeedsReflowCallback) {
|
|
|
|
nsIReflowCallback* cb = new nsAsyncAccesskeyUpdate(this);
|
|
|
|
if (cb) {
|
|
|
|
PresContext()->PresShell()->PostReflowCallback(cb);
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsReflowCallback = false;
|
2007-09-04 01:46:50 -07:00
|
|
|
}
|
|
|
|
|
2008-09-30 17:57:51 -07:00
|
|
|
nsresult rv = nsLeafBoxFrame::DoLayout(aBoxLayoutState);
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
CalcDrawRect(*aBoxLayoutState.GetRenderingContext());
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleText* textStyle = StyleText();
|
2012-04-26 17:24:54 -07:00
|
|
|
|
2012-04-29 17:34:09 -07:00
|
|
|
nsRect scrollBounds(nsPoint(0, 0), GetSize());
|
2012-04-26 17:24:54 -07:00
|
|
|
nsRect textRect = mTextDrawRect;
|
|
|
|
|
|
|
|
nsRefPtr<nsFontMetrics> fontMet;
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
|
|
|
|
nsBoundingMetrics metrics =
|
2012-04-29 17:34:09 -07:00
|
|
|
fontMet->GetInkBoundsForVisualOverflow(mCroppedTitle.get(),
|
|
|
|
mCroppedTitle.Length(),
|
2012-04-26 17:24:54 -07: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-29 17:34:09 -07: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-26 17:24:54 -07:00
|
|
|
|
2008-09-30 17:57:51 -07:00
|
|
|
if (textStyle->mTextShadow) {
|
2012-04-29 17:34:09 -07:00
|
|
|
// text-shadow extends our visual but not scrollable bounds
|
2010-10-06 21:25:45 -07:00
|
|
|
nsRect &vis = overflow.VisualOverflow();
|
2011-01-02 17:48:09 -08:00
|
|
|
vis.UnionRect(vis, nsLayoutUtils::GetTextShadowRectsUnion(mTextDrawRect, this));
|
2008-09-30 17:57:51 -07:00
|
|
|
}
|
2012-04-26 17:24:54 -07:00
|
|
|
FinishAndStoreOverflow(overflow, GetSize());
|
2011-01-02 17:48:09 -08:00
|
|
|
|
2008-09-30 17:57:51 -07:00
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRect
|
|
|
|
nsTextBoxFrame::GetComponentAlphaBounds()
|
|
|
|
{
|
2013-02-16 13:51:02 -08:00
|
|
|
if (StyleText()->mTextShadow) {
|
2012-07-22 20:00:36 -07:00
|
|
|
return GetVisualOverflowRectRelativeToSelf();
|
|
|
|
}
|
|
|
|
return mTextDrawRect;
|
2011-01-02 17:48:09 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-11-25 14:59:06 -08:00
|
|
|
nsTextBoxFrame::ComputesOwnOverflowArea()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-11-25 14:59:06 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* virtual */ void
|
|
|
|
nsTextBoxFrame::MarkIntrinsicWidthsDirty()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsRecalc = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTextBoxFrameSuper::MarkIntrinsicWidthsDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-07 21:18:43 -07:00
|
|
|
nsTextBoxFrame::GetTextSize(nsPresContext* aPresContext,
|
|
|
|
nsRenderingContext& aRenderingContext,
|
|
|
|
const nsString& aString,
|
|
|
|
nsSize& aSize, nscoord& aAscent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-07 18:05:49 -07:00
|
|
|
nsRefPtr<nsFontMetrics> fontMet;
|
2007-08-07 12:07:43 -07:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
|
2011-04-07 21:18:43 -07:00
|
|
|
aSize.height = fontMet->MaxHeight();
|
2007-03-22 10:30:00 -07:00
|
|
|
aRenderingContext.SetFont(fontMet);
|
|
|
|
aSize.width =
|
2011-04-07 21:18:43 -07:00
|
|
|
nsLayoutUtils::GetStringWidth(this, &aRenderingContext,
|
|
|
|
aString.get(), aString.Length());
|
|
|
|
aAscent = fontMet->MaxAscent();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTextBoxFrame::CalcTextSize(nsBoxLayoutState& aBoxLayoutState)
|
|
|
|
{
|
|
|
|
if (mNeedsRecalc)
|
|
|
|
{
|
|
|
|
nsSize size;
|
|
|
|
nsPresContext* presContext = aBoxLayoutState.PresContext();
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* rendContext = aBoxLayoutState.GetRenderingContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (rendContext) {
|
|
|
|
GetTextSize(presContext, *rendContext,
|
|
|
|
mTitle, size, mAscent);
|
|
|
|
mTextSize = size;
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsRecalc = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
void
|
2011-04-07 18:04:40 -07:00
|
|
|
nsTextBoxFrame::CalcDrawRect(nsRenderingContext &aRenderingContext)
|
2008-09-30 17:57:51 -07:00
|
|
|
{
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRect textRect(nsPoint(0, 0), GetSize());
|
2008-10-21 00:43:58 -07:00
|
|
|
nsMargin borderPadding;
|
|
|
|
GetBorderAndPadding(borderPadding);
|
|
|
|
textRect.Deflate(borderPadding);
|
2011-01-02 17:48:09 -08:00
|
|
|
|
2008-09-30 17:57:51 -07:00
|
|
|
// determine (cropped) title and underline position
|
|
|
|
nsPresContext* presContext = PresContext();
|
2011-01-02 17:48:09 -08:00
|
|
|
// determine (cropped) title which fits in aRect.width and its width
|
|
|
|
nscoord titleWidth =
|
|
|
|
CalculateTitleForWidth(presContext, aRenderingContext, textRect.width);
|
2013-02-28 20:06:16 -08: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-02 17:48:09 -08:00
|
|
|
// determine if and at which position to put the underline
|
|
|
|
UpdateAccessIndex();
|
2008-09-30 17:57:51 -07:00
|
|
|
|
|
|
|
// make the rect as small as our (cropped) text.
|
|
|
|
nscoord outerWidth = textRect.width;
|
2011-01-02 17:48:09 -08:00
|
|
|
textRect.width = titleWidth;
|
2008-09-30 17:57:51 -07:00
|
|
|
|
|
|
|
// Align our text within the overall rect by checking our text-align property.
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleVisibility* vis = StyleVisibility();
|
|
|
|
const nsStyleText* textStyle = StyleText();
|
2008-09-30 17:57:51 -07:00
|
|
|
|
|
|
|
if (textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_CENTER)
|
|
|
|
textRect.x += (outerWidth - textRect.width)/2;
|
2009-02-05 19:48:30 -08: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-09-30 17:57:51 -07:00
|
|
|
}
|
2011-01-02 17:48:09 -08:00
|
|
|
|
|
|
|
mTextDrawRect = textRect;
|
2008-09-30 17:57:51 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Ok return our dimensions
|
|
|
|
*/
|
|
|
|
nsSize
|
|
|
|
nsTextBoxFrame::GetPrefSize(nsBoxLayoutState& aBoxLayoutState)
|
|
|
|
{
|
|
|
|
CalcTextSize(aBoxLayoutState);
|
|
|
|
|
|
|
|
nsSize size = mTextSize;
|
|
|
|
DISPLAY_PREF_SIZE(this, size);
|
|
|
|
|
|
|
|
AddBorderAndPadding(size);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool widthSet, heightSet;
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame::AddCSSPrefSize(this, size, widthSet, heightSet);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ok return our dimensions
|
|
|
|
*/
|
|
|
|
nsSize
|
|
|
|
nsTextBoxFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState)
|
|
|
|
{
|
|
|
|
CalcTextSize(aBoxLayoutState);
|
|
|
|
|
|
|
|
nsSize size = mTextSize;
|
|
|
|
DISPLAY_MIN_SIZE(this, size);
|
|
|
|
|
|
|
|
// if there is cropping our min width becomes our border and padding
|
|
|
|
if (mCropType != CropNone)
|
|
|
|
size.width = 0;
|
|
|
|
|
|
|
|
AddBorderAndPadding(size);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool widthSet, heightSet;
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame::AddCSSMinSize(aBoxLayoutState, this, size, widthSet, heightSet);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsTextBoxFrame::GetBoxAscent(nsBoxLayoutState& aBoxLayoutState)
|
|
|
|
{
|
|
|
|
CalcTextSize(aBoxLayoutState);
|
|
|
|
|
|
|
|
nscoord ascent = mAscent;
|
|
|
|
|
|
|
|
nsMargin m(0,0,0,0);
|
|
|
|
GetBorderAndPadding(m);
|
|
|
|
ascent += m.top;
|
|
|
|
|
|
|
|
return ascent;
|
|
|
|
}
|
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTextBoxFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
MakeFrameName(NS_LITERAL_STRING("TextBox"), aResult);
|
|
|
|
aResult += NS_LITERAL_STRING("[value=") + mTitle + NS_LITERAL_STRING("]");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// If you make changes to this function, check its counterparts
|
2008-12-29 07:07:38 -08:00
|
|
|
// in nsBoxFrame and nsXULLabelFrame
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
nsTextBoxFrame::RegUnregAccessKey(bool aDoReg)
|
2007-03-22 10:30:00 -07: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.
|
|
|
|
if (!mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::control))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// see if we even have an access key
|
|
|
|
nsAutoString accessKey;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
|
|
|
|
|
|
|
|
if (accessKey.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// With a valid PresContext we can get the ESM
|
|
|
|
// and (un)register the access key
|
2014-03-31 21:09:23 -07:00
|
|
|
EventStateManager* esm = PresContext()->EventStateManager();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t key = accessKey.First();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aDoReg)
|
2011-04-21 10:35:52 -07:00
|
|
|
esm->RegisterAccessKey(mContent, key);
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
2011-04-21 10:35:52 -07:00
|
|
|
esm->UnregisterAccessKey(mContent, key);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-21 10:35:52 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|