2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-08-06 05:13:07 +00:00
|
|
|
|
|
|
|
#include "nsGfxButtonControlFrame.h"
|
2004-10-14 19:05:31 +00:00
|
|
|
#include "nsIFormControl.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2004-01-28 00:18:22 +00:00
|
|
|
#include "nsStyleSet.h"
|
2004-12-17 20:40:48 +00:00
|
|
|
#include "nsContentUtils.h"
|
2002-05-23 11:25:58 +00:00
|
|
|
// MouseEvent suppression in PP
|
2012-07-01 23:45:59 +00:00
|
|
|
#include "nsContentList.h"
|
2001-04-01 01:01:33 +00:00
|
|
|
|
2006-02-13 19:42:08 +00:00
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
2013-04-04 12:01:08 +00:00
|
|
|
#include "nsTextNode.h"
|
2001-02-06 01:31:18 +00:00
|
|
|
|
2013-10-02 03:46:03 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2006-03-26 21:30:36 +00:00
|
|
|
nsGfxButtonControlFrame::nsGfxButtonControlFrame(nsStyleContext* aContext):
|
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 05:38:33 +00:00
|
|
|
nsHTMLButtonControlFrame(aContext)
|
1999-08-10 19:13:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-11-04 02:38:33 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewGfxButtonControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-08-06 05:13:07 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsGfxButtonControlFrame(aContext);
|
1999-08-06 05:13:07 +00:00
|
|
|
}
|
2007-02-18 17:34:09 +00:00
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsGfxButtonControlFrame)
|
|
|
|
|
2009-12-24 05:21:15 +00:00
|
|
|
void nsGfxButtonControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-02-18 17:34:09 +00:00
|
|
|
{
|
|
|
|
nsContentUtils::DestroyAnonymousContent(&mTextContent);
|
2009-12-24 05:21:15 +00:00
|
|
|
nsHTMLButtonControlFrame::DestroyFrom(aDestructRoot);
|
2007-02-18 17:34:09 +00:00
|
|
|
}
|
|
|
|
|
2003-10-31 20:19:18 +00:00
|
|
|
nsIAtom*
|
|
|
|
nsGfxButtonControlFrame::GetType() const
|
2001-06-30 00:25:09 +00:00
|
|
|
{
|
2006-12-26 17:47:52 +00:00
|
|
|
return nsGkAtoms::gfxButtonControlFrame;
|
2001-06-30 00:25:09 +00:00
|
|
|
}
|
1999-08-10 19:13:57 +00:00
|
|
|
|
2014-01-05 23:31:14 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-18 07:47:48 +00:00
|
|
|
nsresult
|
2001-11-14 01:33:42 +00:00
|
|
|
nsGfxButtonControlFrame::GetFrameName(nsAString& aResult) const
|
1999-08-06 05:13:07 +00:00
|
|
|
{
|
2001-11-14 01:33:42 +00:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("ButtonControl"), aResult);
|
1999-08-10 19:13:57 +00:00
|
|
|
}
|
1999-11-01 22:12:45 +00:00
|
|
|
#endif
|
1999-08-06 05:13:07 +00:00
|
|
|
|
2000-02-21 05:55:25 +00:00
|
|
|
// Create the text content used as label for the button.
|
|
|
|
// The frame will be generated by the frame constructor.
|
2007-02-18 17:34:09 +00:00
|
|
|
nsresult
|
2011-05-06 20:04:44 +00:00
|
|
|
nsGfxButtonControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
2000-02-21 05:55:25 +00:00
|
|
|
{
|
2006-02-13 19:42:08 +00:00
|
|
|
nsXPIDLString label;
|
|
|
|
GetLabel(label);
|
2007-02-18 17:34:09 +00:00
|
|
|
|
2000-02-21 05:55:25 +00:00
|
|
|
// Add a child text content node for the label
|
2013-04-04 12:01:08 +00:00
|
|
|
mTextContent = new nsTextNode(mContent->NodeInfo()->NodeInfoManager());
|
2007-02-18 17:34:09 +00:00
|
|
|
|
|
|
|
// set the value of the text node and add it to the child list
|
2011-10-17 14:59:28 +00:00
|
|
|
mTextContent->SetText(label, false);
|
2013-04-04 12:01:08 +00:00
|
|
|
aElements.AppendElement(mTextContent);
|
|
|
|
|
2005-10-28 11:25:24 +00:00
|
|
|
return NS_OK;
|
2000-02-21 05:55:25 +00:00
|
|
|
}
|
|
|
|
|
2010-02-11 17:34:01 +00:00
|
|
|
void
|
2010-10-15 15:34:35 +00:00
|
|
|
nsGfxButtonControlFrame::AppendAnonymousContentTo(nsBaseContentList& aElements,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aFilter)
|
2010-02-11 17:34:01 +00:00
|
|
|
{
|
|
|
|
aElements.MaybeAppendElement(mTextContent);
|
|
|
|
}
|
|
|
|
|
2000-08-23 10:38:42 +00:00
|
|
|
// Create the text content used as label for the button.
|
|
|
|
// The frame will be generated by the frame constructor.
|
2007-02-18 17:34:09 +00:00
|
|
|
nsIFrame*
|
|
|
|
nsGfxButtonControlFrame::CreateFrameFor(nsIContent* aContent)
|
2000-08-23 10:38:42 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
nsIFrame * newFrame = nullptr;
|
2000-08-23 10:38:42 +00:00
|
|
|
|
2006-07-19 04:36:36 +00:00
|
|
|
if (aContent == mTextContent) {
|
2000-08-23 10:38:42 +00:00
|
|
|
nsIFrame * parentFrame = mFrames.FirstChild();
|
|
|
|
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext* presContext = PresContext();
|
2003-02-22 00:32:13 +00:00
|
|
|
nsRefPtr<nsStyleContext> textStyleContext;
|
2007-02-18 17:34:09 +00:00
|
|
|
textStyleContext = presContext->StyleSet()->
|
2007-06-16 05:11:20 +00:00
|
|
|
ResolveStyleForNonElement(mStyleContext);
|
2000-08-23 10:38:42 +00:00
|
|
|
|
2013-08-03 04:11:06 +00:00
|
|
|
newFrame = NS_NewTextFrame(presContext->PresShell(), textStyleContext);
|
2013-08-03 04:11:06 +00:00
|
|
|
// initialize the text frame
|
|
|
|
newFrame->Init(mTextContent, parentFrame, nullptr);
|
|
|
|
mTextContent->SetPrimaryFrame(newFrame);
|
2000-08-23 10:38:42 +00:00
|
|
|
}
|
|
|
|
|
2007-02-18 17:34:09 +00:00
|
|
|
return newFrame;
|
|
|
|
}
|
|
|
|
|
2009-01-12 19:20:59 +00:00
|
|
|
NS_QUERYFRAME_HEAD(nsGfxButtonControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsHTMLButtonControlFrame)
|
2000-02-21 05:55:25 +00:00
|
|
|
|
|
|
|
// Initially we hardcoded the default strings here.
|
|
|
|
// Next, we used html.css to store the default label for various types
|
|
|
|
// of buttons. (nsGfxButtonControlFrame::DoNavQuirksReflow rev 1.20)
|
|
|
|
// However, since html.css is not internationalized, we now grab the default
|
|
|
|
// label from a string bundle as is done for all other UI strings.
|
|
|
|
// See bug 16999 for further details.
|
2002-09-16 06:23:52 +00:00
|
|
|
nsresult
|
2012-09-11 10:26:29 +00:00
|
|
|
nsGfxButtonControlFrame::GetDefaultLabel(nsXPIDLString& aString) const
|
2000-02-21 05:55:25 +00:00
|
|
|
{
|
2005-12-12 23:53:06 +00:00
|
|
|
nsCOMPtr<nsIFormControl> form = do_QueryInterface(mContent);
|
|
|
|
NS_ENSURE_TRUE(form, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t type = form->GetType();
|
2004-12-17 20:40:48 +00:00
|
|
|
const char *prop;
|
2002-09-16 06:23:52 +00:00
|
|
|
if (type == NS_FORM_INPUT_RESET) {
|
2004-12-17 20:40:48 +00:00
|
|
|
prop = "Reset";
|
2012-09-11 10:26:29 +00:00
|
|
|
}
|
2002-09-16 06:23:52 +00:00
|
|
|
else if (type == NS_FORM_INPUT_SUBMIT) {
|
2004-12-17 20:40:48 +00:00
|
|
|
prop = "Submit";
|
2012-09-11 10:26:29 +00:00
|
|
|
}
|
2000-02-21 05:55:25 +00:00
|
|
|
else {
|
2004-01-29 22:04:45 +00:00
|
|
|
aString.Truncate();
|
2004-12-17 20:40:48 +00:00
|
|
|
return NS_OK;
|
2000-02-21 05:55:25 +00:00
|
|
|
}
|
2004-12-17 20:40:48 +00:00
|
|
|
|
|
|
|
return nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
|
|
|
|
prop, aString);
|
2000-02-21 05:55:25 +00:00
|
|
|
}
|
|
|
|
|
2006-02-13 19:42:08 +00:00
|
|
|
nsresult
|
|
|
|
nsGfxButtonControlFrame::GetLabel(nsXPIDLString& aLabel)
|
|
|
|
{
|
2006-04-04 22:34:10 +00:00
|
|
|
// Get the text from the "value" property on our content if there is
|
|
|
|
// one; otherwise set it to a default value (localized).
|
|
|
|
nsresult rv;
|
2006-02-13 19:42:08 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> elt = do_QueryInterface(mContent);
|
2006-04-04 22:34:10 +00:00
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::value) && elt) {
|
2006-02-13 19:42:08 +00:00
|
|
|
rv = elt->GetValue(aLabel);
|
2006-04-04 22:34:10 +00:00
|
|
|
} else {
|
2006-02-13 19:42:08 +00:00
|
|
|
// Generate localized label.
|
|
|
|
// We can't make any assumption as to what the default would be
|
|
|
|
// because the value is localized for non-english platforms, thus
|
|
|
|
// it might not be the string "Reset", "Submit Query", or "Browse..."
|
|
|
|
rv = GetDefaultLabel(aLabel);
|
|
|
|
}
|
|
|
|
|
2006-04-04 22:34:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Compress whitespace out of label if needed.
|
2013-02-16 21:51:02 +00:00
|
|
|
if (!StyleText()->WhiteSpaceIsSignificant()) {
|
2006-02-13 19:42:08 +00:00
|
|
|
aLabel.CompressWhitespace();
|
|
|
|
} else if (aLabel.Length() > 2 && aLabel.First() == ' ' &&
|
|
|
|
aLabel.CharAt(aLabel.Length() - 1) == ' ') {
|
|
|
|
// This is a bit of a hack. The reason this is here is as follows: we now
|
|
|
|
// have default padding on our buttons to make them non-ugly.
|
|
|
|
// Unfortunately, IE-windows does not have such padding, so people will
|
|
|
|
// stick values like " ok " (with the spaces) in the buttons in an attempt
|
|
|
|
// to make them look decent. Unfortunately, if they do this the button
|
|
|
|
// looks way too big in Mozilla. Worse yet, if they do this _and_ set a
|
|
|
|
// fixed width for the button we run into trouble because our focus-rect
|
|
|
|
// border/padding and outer border take up 10px of the horizontal button
|
|
|
|
// space or so; the result is that the text is misaligned, even with the
|
2013-10-02 16:04:09 +00:00
|
|
|
// recentering we do in nsHTMLButtonControlFrame::Reflow. So to solve
|
|
|
|
// this, even if the whitespace is significant, single leading and trailing
|
|
|
|
// _spaces_ (and not other whitespace) are removed. The proper solution,
|
|
|
|
// of course, is to not have the focus rect painting taking up 6px of
|
2006-02-13 19:42:08 +00:00
|
|
|
// horizontal space. We should do that instead (via XBL form controls or
|
|
|
|
// changing the renderer) and remove this.
|
|
|
|
aLabel.Cut(0, 1);
|
|
|
|
aLabel.Truncate(aLabel.Length() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGfxButtonControlFrame::AttributeChanged(int32_t aNameSpaceID,
|
2004-12-31 01:13:27 +00:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aModType)
|
2000-02-21 05:55:25 +00:00
|
|
|
{
|
2000-02-23 20:56:39 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2000-02-21 05:55:25 +00:00
|
|
|
// If the value attribute is set, update the text of the label
|
2006-12-26 17:47:52 +00:00
|
|
|
if (nsGkAtoms::value == aAttribute) {
|
2000-02-23 20:56:39 +00:00
|
|
|
if (mTextContent && mContent) {
|
2006-02-13 19:42:08 +00:00
|
|
|
nsXPIDLString label;
|
|
|
|
rv = GetLabel(label);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mTextContent->SetText(label, true);
|
2000-02-23 20:56:39 +00:00
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
2000-02-21 05:55:25 +00:00
|
|
|
}
|
|
|
|
|
2000-02-23 20:56:39 +00:00
|
|
|
// defer to HTMLButtonControlFrame
|
|
|
|
} else {
|
2005-09-07 16:49:21 +00:00
|
|
|
rv = nsHTMLButtonControlFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
2000-02-23 20:56:39 +00:00
|
|
|
}
|
|
|
|
return rv;
|
2000-02-21 05:55:25 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2005-08-16 22:52:48 +00:00
|
|
|
nsGfxButtonControlFrame::IsLeaf() const
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2005-08-16 22:52:48 +00:00
|
|
|
}
|
|
|
|
|
2007-02-17 14:14:08 +00:00
|
|
|
nsIFrame*
|
|
|
|
nsGfxButtonControlFrame::GetContentInsertionFrame()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
nsresult
|
2004-07-31 23:15:21 +00:00
|
|
|
nsGfxButtonControlFrame::HandleEvent(nsPresContext* aPresContext,
|
2013-10-02 03:46:03 +00:00
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
1999-08-06 05:13:07 +00:00
|
|
|
{
|
1999-08-10 19:13:57 +00:00
|
|
|
// Override the HandleEvent to prevent the nsFrame::HandleEvent
|
|
|
|
// from being called. The nsFrame::HandleEvent causes the button label
|
|
|
|
// to be selected (Drawn with an XOR rectangle over the label)
|
|
|
|
|
2000-08-08 23:38:00 +00:00
|
|
|
// do we have user-input style?
|
2013-02-16 21:51:02 +00:00
|
|
|
const nsStyleUserInterface* uiStyle = StyleUserInterface();
|
2000-08-08 23:38:00 +00:00
|
|
|
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE || uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED)
|
|
|
|
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
|
1999-08-10 19:13:57 +00:00
|
|
|
return NS_OK;
|
1999-08-06 05:13:07 +00:00
|
|
|
}
|