gecko-dev/layout/forms/nsSelectsAreaFrame.cpp

104 строки
2.8 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsSelectsAreaFrame.h"
#include "nsCOMPtr.h"
#include "nsIDOMHTMLOptionElement.h"
#include "nsIContent.h"
#include "nsIAreaFrame.h"
static NS_DEFINE_IID(kAreaFrameIID, NS_IAREAFRAME_IID);
nsresult
NS_NewSelectsAreaFrame(nsIFrame** aNewFrame, PRUint32 aFlags)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsSelectsAreaFrame* it = new nsSelectsAreaFrame;
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
it->SetFlags(aFlags);
*aNewFrame = it;
return NS_OK;
}
/*NS_IMETHODIMP
nsSelectsAreaFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kAreaFrameIID)) {
nsIAreaFrame* tmp = (nsIAreaFrame*)this;
*aInstancePtr = (void*)tmp;
return NS_OK;
}
return nsAreaFrame::QueryInterface(aIID, aInstancePtr);
}
*/
//---------------------------------------------------------
PRBool
nsSelectsAreaFrame::IsOptionElement(nsIContent* aContent)
{
PRBool result = PR_FALSE;
nsCOMPtr<nsIDOMHTMLOptionElement> optElem;
if (NS_SUCCEEDED(aContent->QueryInterface(nsCOMTypeInfo<nsIDOMHTMLOptionElement>::GetIID(),(void**) getter_AddRefs(optElem)))) {
if (optElem != nsnull) {
result = PR_TRUE;
}
}
return result;
}
//---------------------------------------------------------
PRBool
nsSelectsAreaFrame::IsOptionElementFrame(nsIFrame *aFrame)
{
nsIContent *content = nsnull;
aFrame->GetContent(&content);
PRBool result = PR_FALSE;
if (nsnull != content) {
result = IsOptionElement(content);
NS_RELEASE(content);
}
return(result);
}
//---------------------------------------------------------
NS_IMETHODIMP
nsSelectsAreaFrame::GetFrameForPoint(const nsPoint& aPoint, nsIFrame** aFrame)
{
nsAreaFrame::GetFrameForPoint(aPoint, aFrame);
nsIFrame* selectedFrame = *aFrame;
while ((nsnull != selectedFrame) && (PR_FALSE == IsOptionElementFrame(selectedFrame))) {
selectedFrame->GetParent(&selectedFrame);
}
if (nsnull != selectedFrame) {
*aFrame = selectedFrame;
}
return NS_OK;
}