2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:30:37 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-11-09 23:30:16 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-11-09 23:30:16 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-11-09 23:30:16 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:30:37 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-28 20:14:13 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 14:30:37 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 14:30:37 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2001-11-02 07:40:01 +00:00
|
|
|
#include "nsIImageControlFrame.h"
|
1999-04-13 21:51:43 +00:00
|
|
|
#include "nsImageFrame.h"
|
1998-11-09 23:30:16 +00:00
|
|
|
#include "nsIFormControlFrame.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
1998-11-09 23:30:16 +00:00
|
|
|
#include "nsIPresShell.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsStyleContext.h"
|
1998-11-09 23:30:16 +00:00
|
|
|
#include "nsLeafFrame.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
#include "nsIImage.h"
|
|
|
|
#include "nsStyleConsts.h"
|
2000-02-09 19:34:39 +00:00
|
|
|
#include "nsFormControlFrame.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsGUIEvent.h"
|
2001-11-01 15:31:13 +00:00
|
|
|
#include "nsLayoutAtoms.h"
|
2002-06-04 00:44:04 +00:00
|
|
|
#include "nsIServiceManager.h"
|
2002-09-30 11:56:37 +00:00
|
|
|
#include "nsContainerFrame.h"
|
2005-08-23 03:57:07 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2001-08-17 03:13:07 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
2001-05-11 21:11:38 +00:00
|
|
|
#include "nsIAccessibilityService.h"
|
2001-08-17 03:13:07 +00:00
|
|
|
#endif
|
1998-11-09 23:30:16 +00:00
|
|
|
|
1998-11-20 17:22:08 +00:00
|
|
|
#define nsImageControlFrameSuper nsImageFrame
|
|
|
|
class nsImageControlFrame : public nsImageControlFrameSuper,
|
2001-11-02 07:40:01 +00:00
|
|
|
public nsIFormControlFrame,
|
|
|
|
public nsIImageControlFrame
|
1998-11-09 23:30:16 +00:00
|
|
|
{
|
|
|
|
public:
|
2006-03-26 21:30:36 +00:00
|
|
|
nsImageControlFrame(nsStyleContext* aContext);
|
1999-11-04 23:16:47 +00:00
|
|
|
~nsImageControlFrame();
|
1998-11-09 23:30:16 +00:00
|
|
|
|
2006-04-10 00:16:29 +00:00
|
|
|
virtual void Destroy();
|
2000-05-16 12:44:32 +00:00
|
|
|
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
1998-11-09 23:30:16 +00:00
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
NS_IMETHOD Reflow(nsPresContext* aPresContext,
|
1999-04-27 00:06:03 +00:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
NS_IMETHOD HandleEvent(nsPresContext* aPresContext,
|
1998-11-09 23:30:16 +00:00
|
|
|
nsGUIEvent* aEvent,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aEventStatus);
|
1998-11-09 23:30:16 +00:00
|
|
|
|
2003-10-31 20:19:18 +00:00
|
|
|
virtual nsIAtom* GetType() const;
|
2001-11-01 15:31:13 +00:00
|
|
|
|
2001-08-17 03:13:07 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
2001-05-17 23:52:32 +00:00
|
|
|
NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
|
2001-08-17 03:13:07 +00:00
|
|
|
#endif
|
2001-05-17 23:52:32 +00:00
|
|
|
|
1999-11-01 22:12:45 +00:00
|
|
|
#ifdef DEBUG
|
2001-11-14 01:33:42 +00:00
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const {
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("ImageControl"), aResult);
|
1998-11-19 17:22:29 +00:00
|
|
|
}
|
1999-11-01 22:12:45 +00:00
|
|
|
#endif
|
1998-11-19 17:22:29 +00:00
|
|
|
|
2004-12-30 21:56:11 +00:00
|
|
|
NS_IMETHOD GetCursor(const nsPoint& aPoint,
|
|
|
|
nsIFrame::Cursor& aCursor);
|
2005-12-12 23:53:06 +00:00
|
|
|
// nsIFormContromFrame
|
|
|
|
virtual void SetFocus(PRBool aOn, PRBool aRepaint);
|
|
|
|
virtual nsresult SetFormProperty(nsIAtom* aName, const nsAString& aValue);
|
|
|
|
virtual nsresult GetFormProperty(nsIAtom* aName, nsAString& aValue) const;
|
2001-11-02 07:40:01 +00:00
|
|
|
|
|
|
|
// nsIImageControlFrame
|
|
|
|
NS_IMETHOD GetClickedX(PRInt32* aX);
|
|
|
|
NS_IMETHOD GetClickedY(PRInt32* aY);
|
1999-01-22 15:32:57 +00:00
|
|
|
|
1998-11-09 23:30:16 +00:00
|
|
|
protected:
|
|
|
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
|
|
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
|
|
|
|
|
|
|
nsPoint mLastClickPoint;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-03-26 21:30:36 +00:00
|
|
|
nsImageControlFrame::nsImageControlFrame(nsStyleContext* aContext):
|
|
|
|
nsImageControlFrameSuper(aContext)
|
1998-11-09 23:30:16 +00:00
|
|
|
{
|
|
|
|
mLastClickPoint = nsPoint(0,0);
|
|
|
|
}
|
|
|
|
|
1999-11-04 23:16:47 +00:00
|
|
|
nsImageControlFrame::~nsImageControlFrame()
|
|
|
|
{
|
2000-05-16 12:44:32 +00:00
|
|
|
}
|
|
|
|
|
2006-04-10 00:16:29 +00:00
|
|
|
void
|
|
|
|
nsImageControlFrame::Destroy()
|
2000-05-16 12:44:32 +00:00
|
|
|
{
|
2006-04-10 00:16:29 +00:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(NS_STATIC_CAST(nsIFrame*, this), PR_FALSE);
|
|
|
|
nsImageControlFrameSuper::Destroy();
|
1999-11-04 23:16:47 +00:00
|
|
|
}
|
|
|
|
|
2005-11-01 20:40:54 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewImageControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1998-11-09 23:30:16 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsImageControlFrame(aContext);
|
1998-11-09 23:30:16 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 01:50:15 +00:00
|
|
|
// Frames are not refcounted, no need to AddRef
|
|
|
|
NS_IMETHODIMP
|
1998-11-09 23:30:16 +00:00
|
|
|
nsImageControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(0 != aInstancePtr, "null ptr");
|
|
|
|
if (NULL == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2001-01-04 20:44:42 +00:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) {
|
1998-11-09 23:30:16 +00:00
|
|
|
*aInstancePtr = (void*) ((nsIFormControlFrame*) this);
|
|
|
|
return NS_OK;
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
2001-11-02 07:40:01 +00:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIImageControlFrame))) {
|
|
|
|
*aInstancePtr = (void*) ((nsIImageControlFrame*) this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-05-11 21:11:38 +00:00
|
|
|
|
1998-11-20 17:22:08 +00:00
|
|
|
return nsImageControlFrameSuper::QueryInterface(aIID, aInstancePtr);
|
1998-11-09 23:30:16 +00:00
|
|
|
}
|
|
|
|
|
2001-08-17 03:13:07 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
2001-05-17 23:52:32 +00:00
|
|
|
NS_IMETHODIMP nsImageControlFrame::GetAccessible(nsIAccessible** aAccessible)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
|
|
|
|
if (accService) {
|
2005-03-27 03:03:11 +00:00
|
|
|
if (mContent->Tag() == nsHTMLAtoms::button) {
|
|
|
|
return accService->CreateHTML4ButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
|
|
|
}
|
|
|
|
else if (mContent->Tag() == nsHTMLAtoms::input) {
|
|
|
|
return accService->CreateHTMLButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
|
|
|
}
|
2001-05-17 23:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-08-17 03:13:07 +00:00
|
|
|
#endif
|
2001-05-17 23:52:32 +00:00
|
|
|
|
1998-11-09 23:30:16 +00:00
|
|
|
nsrefcnt nsImageControlFrame::AddRef(void)
|
|
|
|
{
|
|
|
|
NS_WARNING("not supported");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsrefcnt nsImageControlFrame::Release(void)
|
|
|
|
{
|
|
|
|
NS_WARNING("not supported");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-10-31 20:19:18 +00:00
|
|
|
nsIAtom*
|
|
|
|
nsImageControlFrame::GetType() const
|
2001-11-01 15:31:13 +00:00
|
|
|
{
|
2003-10-31 20:19:18 +00:00
|
|
|
return nsLayoutAtoms::imageControlFrame;
|
2001-11-01 15:31:13 +00:00
|
|
|
}
|
|
|
|
|
1999-04-27 00:06:03 +00:00
|
|
|
NS_METHOD
|
2004-07-31 23:15:21 +00:00
|
|
|
nsImageControlFrame::Reflow(nsPresContext* aPresContext,
|
1999-04-27 00:06:03 +00:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2000-04-21 21:51:35 +00:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsImageControlFrame", aReflowState.reason);
|
2001-11-14 13:40:03 +00:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
2002-06-04 00:44:04 +00:00
|
|
|
if (aReflowState.reason == eReflowReason_Initial) {
|
2006-04-10 00:16:29 +00:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(NS_STATIC_CAST(nsIFrame*, this), PR_TRUE);
|
1998-11-09 23:30:16 +00:00
|
|
|
}
|
1999-04-27 00:06:03 +00:00
|
|
|
return nsImageControlFrameSuper::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
1998-11-09 23:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
2004-07-31 23:15:21 +00:00
|
|
|
nsImageControlFrame::HandleEvent(nsPresContext* aPresContext,
|
1999-01-27 00:25:40 +00:00
|
|
|
nsGUIEvent* aEvent,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
1998-11-09 23:30:16 +00:00
|
|
|
{
|
1999-11-24 06:03:41 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
2000-08-08 23:38:00 +00:00
|
|
|
|
2002-05-01 20:15:44 +00:00
|
|
|
// Don't do anything if the event has already been handled by someone
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-08 23:38:00 +00:00
|
|
|
// do we have user-input style?
|
2003-05-15 03:42:21 +00:00
|
|
|
const nsStyleUserInterface* uiStyle = GetStyleUserInterface();
|
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);
|
|
|
|
|
2006-07-06 10:43:51 +00:00
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled)) { // XXX cache disabled
|
1998-11-09 23:30:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-24 06:03:41 +00:00
|
|
|
*aEventStatus = nsEventStatus_eIgnore;
|
1998-11-09 23:30:16 +00:00
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
switch (aEvent->message) {
|
2000-08-03 22:17:14 +00:00
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
1999-01-27 00:25:40 +00:00
|
|
|
{
|
|
|
|
// Store click point for GetNamesValues
|
2004-03-06 04:48:15 +00:00
|
|
|
// Do this on MouseUp because the specs don't say and that's what IE does
|
2005-08-23 03:57:07 +00:00
|
|
|
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this);
|
|
|
|
TranslateEventCoords(pt, mLastClickPoint);
|
1999-01-27 00:25:40 +00:00
|
|
|
break;
|
1998-11-09 23:30:16 +00:00
|
|
|
}
|
|
|
|
}
|
1998-11-20 17:22:08 +00:00
|
|
|
return nsImageControlFrameSuper::HandleEvent(aPresContext, aEvent,
|
|
|
|
aEventStatus);
|
1998-11-09 23:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsImageControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-04-27 22:54:15 +00:00
|
|
|
NS_IMETHODIMP
|
2004-12-30 21:56:11 +00:00
|
|
|
nsImageControlFrame::GetCursor(const nsPoint& aPoint,
|
|
|
|
nsIFrame::Cursor& aCursor)
|
1999-04-27 22:54:15 +00:00
|
|
|
{
|
1999-06-25 00:19:44 +00:00
|
|
|
// Use style defined cursor if one is provided, otherwise when
|
|
|
|
// the cursor style is "auto" we use the pointer cursor.
|
2004-12-30 21:56:11 +00:00
|
|
|
FillCursorInformationFromStyle(GetStyleUserInterface(), aCursor);
|
|
|
|
|
|
|
|
if (NS_STYLE_CURSOR_AUTO == aCursor.mCursor) {
|
|
|
|
aCursor.mCursor = NS_STYLE_CURSOR_POINTER;
|
1999-06-25 00:19:44 +00:00
|
|
|
}
|
2004-12-30 21:56:11 +00:00
|
|
|
|
1999-04-27 22:54:15 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-11-09 23:30:16 +00:00
|
|
|
|
2005-12-12 23:53:06 +00:00
|
|
|
nsresult
|
|
|
|
nsImageControlFrame::SetFormProperty(nsIAtom* aName,
|
|
|
|
const nsAString& aValue)
|
1999-01-25 22:16:27 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-12-12 23:53:06 +00:00
|
|
|
nsresult
|
|
|
|
nsImageControlFrame::GetFormProperty(nsIAtom* aName,
|
|
|
|
nsAString& aValue) const
|
1999-01-25 22:16:27 +00:00
|
|
|
{
|
2000-08-23 17:27:06 +00:00
|
|
|
aValue.Truncate();
|
1999-01-25 22:16:27 +00:00
|
|
|
return NS_OK;
|
1999-01-27 00:25:40 +00:00
|
|
|
}
|
fixed bugs #6303, #6753, #6756, #6759
Re-wrote nsComboboxFrame.
removed the obsolete nsHTMLAtoms: comboText,comoTextSelected,comTextSelectedFocus,dropDownVisible,
dropdownHidden, dropDownBtnOut, dropDownBtnPressed,
Added nsHTMLAtoms::combobox, nsLayoutAtoms::popupList
Renamed dropDownList to dropDownListPseudo
Added "arrow.gif" as to be used the background-image for the combobox button
ua.css - added rules for select to differentiate between comboboxes and listboxes.
Added style rules to more closely match the XPTOOLKIT XPWidgets look.
removed the following :-moz-combobox-text, -moz-combobox-textselected
nsIFormControlFrame.h - Added SetSuggestedSize method.
nsButtonControlFrame - Implemented SetSuggestedSize.
nsCSSFrameConstructor.cpp - Rewrote ConstructSelectFrame.
nsIWidget.h -Added GetAbsoluteBounds method.
nsWindow.cpp - Implemented GetAbsoluteBounds.
1999-07-14 22:00:24 +00:00
|
|
|
|
2001-11-02 07:40:01 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageControlFrame::GetClickedX(PRInt32* aX)
|
|
|
|
{
|
|
|
|
*aX = mLastClickPoint.x;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageControlFrame::GetClickedY(PRInt32* aY)
|
|
|
|
{
|
|
|
|
*aY = mLastClickPoint.y;
|
|
|
|
return NS_OK;
|
|
|
|
}
|