Compare commits

..

1 Commits

Author SHA1 Message Date
(no author)
c5d6b83e4c This commit was manufactured by cvs2svn to create branch 'CVS'.
git-svn-id: svn://10.0.0.236/branches/CVS@50735 18797224-902f-48f8-a5cc-f745e15eee43
1999-10-14 23:53:00 +00:00
236 changed files with 54379 additions and 22749 deletions

View File

@@ -1,129 +0,0 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/******
This file contains the list of all XUL nsIAtoms and their values
It is designed to be used as inline input to nsXULAtoms.cpp *only*
through the magic of C preprocessing.
All entires must be enclosed in the macro XUL_ATOM which will have cruel
and unusual things done to it
It is recommended (but not strictly necessary) to keep all entries
in alphabetical order
The first argument to XUL_ATOM is the C++ identifier of the atom
The second argument is the string value of the atom
******/
XUL_ATOM(button, "button")
XUL_ATOM(spinner, "spinner")
XUL_ATOM(scrollbar, "scrollbar")
XUL_ATOM(slider, "slider")
XUL_ATOM(colorpicker, "colorpicker")
XUL_ATOM(palettename, "palettename")
XUL_ATOM(fontpicker, "fontpicker")
XUL_ATOM(radio, "radio")
XUL_ATOM(text, "text")
XUL_ATOM(toolbar, "toolbar")
XUL_ATOM(toolbaritem, "toolbaritem")
XUL_ATOM(toolbox, "toolbox")
// The tree atoms
XUL_ATOM(tree, "tree") // The start of a tree view
XUL_ATOM(treecaption, "treecaption") // The caption of a tree view
XUL_ATOM(treehead, "treehead") // The header of the tree view
XUL_ATOM(treerow, "treerow") // A row in the tree view
XUL_ATOM(treecell, "treecell") // An item in the tree view
XUL_ATOM(treeitem, "treeitem") // A cell in the tree view
XUL_ATOM(treechildren, "treechildren") // The children of an item in the tree view
XUL_ATOM(treeindentation, "treeindentation") // Specifies that the indentation for the level should occur here.
XUL_ATOM(allowevents, "allowevents") // Lets events be handled on the cell contents or in menus.
XUL_ATOM(treecol, "treecol") // A column in the tree view
XUL_ATOM(treecolgroup, "treecolgroup") // A column group in the tree view
XUL_ATOM(treefoot, "treefoot") // The footer of the tree view
XUL_ATOM(treepusher, "treepusher") // A column pusher (left or right) for the tree view
XUL_ATOM(scrollbarlist, "scrollbarlist") // An atom for internal use by the tree view
XUL_ATOM(open, "open") // Whether or not a menu, tree, etc. is open
XUL_ATOM(menubar, "menubar") // An XP menu bar.
XUL_ATOM(menu, "menu") // Represents an XP menu
XUL_ATOM(menuitem, "menuitem") // Represents an XP menu item
XUL_ATOM(menupopup, "menupopup") // The XP menu's children.
XUL_ATOM(menuactive, "menuactive") // Whether or not a menu is active (without necessarily being open)
XUL_ATOM(accesskey, "accesskey") // The shortcut key for a menu or menu item
XUL_ATOM(acceltext, "acceltext") // Text to use for the accelerator
XUL_ATOM(popupset, "popupset") // Contains popup menus, context menus, and tooltips
XUL_ATOM(popup, "popup") // The popup for a context menu, popup menu, or tooltip
XUL_ATOM(menugenerated, "menugenerated") // Internal
XUL_ATOM(key, "key") // A key element
XUL_ATOM(broadcaster, "broadcaster") // A broadcaster
XUL_ATOM(observes, "observes") // The observes element
XUL_ATOM(templateAtom, "template") // A XUL template
XUL_ATOM(progressmeter, "progressmeter")
XUL_ATOM(titledbutton, "titledbutton")
XUL_ATOM(crop, "crop")
XUL_ATOM(mode, "mode")
XUL_ATOM(box, "box")
XUL_ATOM(flex, "flex")
XUL_ATOM(spring, "spring")
XUL_ATOM(deck, "deck")
XUL_ATOM(tabcontrol, "tabcontrol")
XUL_ATOM(tab, "tab")
XUL_ATOM(tabpanel, "tabpanel")
XUL_ATOM(tabpage, "tabpage")
XUL_ATOM(tabbox, "tabbox")
XUL_ATOM(index, "index")
XUL_ATOM(maxpos, "maxpos")
XUL_ATOM(curpos, "curpos")
XUL_ATOM(scrollbarbutton, "scrollbarbutton")
XUL_ATOM(increment, "increment")
XUL_ATOM(pageincrement, "pageincrement")
XUL_ATOM(thumb, "thumb")
XUL_ATOM(toggled, "toggled")
XUL_ATOM(grippy, "grippy")
XUL_ATOM(splitter, "splitter")
XUL_ATOM(collapse, "collapse")
XUL_ATOM(resizebefore, "resizebefore")
XUL_ATOM(resizeafter, "resizeafter")
XUL_ATOM(state, "state")
// toolbar & toolbar d&d atoms
XUL_ATOM(tbDropLocation, "tb-droplocation")
XUL_ATOM(tbDropLocationCoord, "tb-droplocationcoord")
XUL_ATOM(tbDropOn, "tb-dropon")
XUL_ATOM(tbTriggerRepaint, "tb-triggerrepaint")
XUL_ATOM(container, "container")
XUL_ATOM(widget, "widget")
XUL_ATOM(window, "window")
XUL_ATOM(iframe, "iframe")
XUL_ATOM(browser, "browser")
XUL_ATOM(editor, "editor")

View File

@@ -1,54 +0,0 @@
/* -*- 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.
*/
#ifndef nsXULAtoms_h___
#define nsXULAtoms_h___
#include "prtypes.h"
#include "nsIAtom.h"
class nsINameSpaceManager;
/**
* This class wraps up the creation and destruction of the standard
* set of xul atoms used during normal xul handling. This object
* is created when the first xul content object is created, and
* destroyed when the last such content object is destroyed.
*/
class nsXULAtoms {
public:
static void AddRefAtoms();
static void ReleaseAtoms();
// XUL namespace ID, good for the life of the nsXULAtoms object
static PRInt32 nameSpaceID;
/* Declare all atoms
The atom names and values are stored in nsCSSAtomList.h and
are brought to you by the magic of C preprocessing
Add new atoms to nsCSSAtomList and all support logic will be auto-generated
*/
#define XUL_ATOM(_name, _value) static nsIAtom* _name;
#include "nsXULAtomList.h"
#undef XUL_ATOM
};
#endif /* nsXULAtoms_h___ */

View File

@@ -1,68 +0,0 @@
/* -*- 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 "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsXULAtoms.h"
static const char kXULNameSpace[] = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
PRInt32 nsXULAtoms::nameSpaceID;
// define storage for all atoms
#define XUL_ATOM(_name, _value) nsIAtom* nsXULAtoms::_name;
#include "nsXULAtomList.h"
#undef XUL_ATOM
static nsrefcnt gRefCnt = 0;
static nsINameSpaceManager* gNameSpaceManager;
void nsXULAtoms::AddRefAtoms() {
if (gRefCnt == 0) {
/* XUL Atoms registers the XUL name space ID because it's a convenient
place to do this, if you don't want a permanent, "well-known" ID.
*/
if (NS_SUCCEEDED(NS_NewNameSpaceManager(&gNameSpaceManager))) {
// gNameSpaceManager->CreateRootNameSpace(namespace);
nsAutoString nameSpace(kXULNameSpace);
gNameSpaceManager->RegisterNameSpace(nameSpace, nameSpaceID);
} else {
NS_ASSERTION(0, "failed to create xul atoms namespace manager");
}
// now register the atoms
#define XUL_ATOM(_name, _value) _name = NS_NewAtom(_value);
#include "nsXULAtomList.h"
#undef XUL_ATOM
}
++gRefCnt;
}
void nsXULAtoms::ReleaseAtoms() {
NS_PRECONDITION(gRefCnt != 0, "bad release of xul atoms");
if (--gRefCnt == 0) {
#define XUL_ATOM(_name, _value) NS_RELEASE(_name);
#include "nsXULAtomList.h"
#undef XUL_ATOM
NS_IF_RELEASE(gNameSpaceManager);
}
}

View File

@@ -0,0 +1,617 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsAVLTree.h"
enum eLean {eLeft,eNeutral,eRight};
struct NS_COM nsAVLNode {
public:
nsAVLNode(void* aValue) {
mLeft=0;
mRight=0;
mSkew=eNeutral;
mValue=aValue;
}
nsAVLNode* mLeft;
nsAVLNode* mRight;
eLean mSkew;
void* mValue;
};
/************************************************************
Now begin the tree class. Don't forget that the comparison
between nodes must occur via the comparitor function,
otherwise all you're testing is pointer addresses.
************************************************************/
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
nsAVLTree::nsAVLTree(nsAVLNodeComparitor& aComparitor,
nsAVLNodeFunctor* aDeallocator) :
mComparitor(aComparitor), mDeallocator(aDeallocator) {
mRoot=0;
mCount=0;
}
static void
avlDeleteTree(nsAVLNode* aNode){
if (aNode) {
avlDeleteTree(aNode->mLeft);
avlDeleteTree(aNode->mRight);
delete aNode;
}
}
/**
*
* @update gess12/27/98
* @param
* @return
*/
nsAVLTree::~nsAVLTree(){
if (mDeallocator) {
ForEachDepthFirst(*mDeallocator);
}
avlDeleteTree(mRoot);
}
class CDoesntExist: public nsAVLNodeFunctor {
public:
CDoesntExist(const nsAVLTree& anotherTree) : mOtherTree(anotherTree) {
}
virtual void* operator()(void* anItem) {
void* result=mOtherTree.FindItem(anItem);
if(result)
return nsnull;
return anItem;
}
protected:
const nsAVLTree& mOtherTree;
};
/**
* This method compares two trees (members by identity).
* @update gess12/27/98
* @param tree to compare against
* @return true if they are identical (contain same stuff).
*/
PRBool nsAVLTree::operator==(const nsAVLTree& aCopy) const{
CDoesntExist functor(aCopy);
void* theItem=FirstThat(functor);
PRBool result=PRBool(!theItem);
return result;
}
/**
*
* @update gess12/27/98
* @param
* @return
*/
static void
avlRotateRight(nsAVLNode*& aRootNode){
nsAVLNode* ptr2;
nsAVLNode* ptr3;
ptr2=aRootNode->mRight;
if(ptr2->mSkew==eRight) {
aRootNode->mRight=ptr2->mLeft;
ptr2->mLeft=aRootNode;
aRootNode->mSkew=eNeutral;
aRootNode=ptr2;
}
else {
ptr3=ptr2->mLeft;
ptr2->mLeft=ptr3->mRight;
ptr3->mRight=ptr2;
aRootNode->mRight=ptr3->mLeft;
ptr3->mLeft=aRootNode;
if(ptr3->mSkew==eLeft)
ptr2->mSkew=eRight;
else ptr2->mSkew=eNeutral;
if(ptr3->mSkew==eRight)
aRootNode->mSkew=eLeft;
else aRootNode->mSkew=eNeutral;
aRootNode=ptr3;
}
aRootNode->mSkew=eNeutral;
return;
}
/**
*
* @update gess12/27/98
* @param
* @return
*/
static void
avlRotateLeft(nsAVLNode*& aRootNode){
nsAVLNode* ptr2;
nsAVLNode* ptr3;
ptr2=aRootNode->mLeft;
if(ptr2->mSkew==eLeft) {
aRootNode->mLeft=ptr2->mRight;
ptr2->mRight=aRootNode;
aRootNode->mSkew=eNeutral;
aRootNode=ptr2;
}
else {
ptr3=ptr2->mRight;
ptr2->mRight=ptr3->mLeft;
ptr3->mLeft=ptr2;
aRootNode->mLeft=ptr3->mRight;
ptr3->mRight=aRootNode;
if(ptr3->mSkew==eRight)
ptr2->mSkew=eLeft;
else ptr2->mSkew=eNeutral;
if(ptr3->mSkew==eLeft)
aRootNode->mSkew=eRight;
else aRootNode->mSkew=eNeutral;
aRootNode=ptr3;
}
aRootNode->mSkew=eNeutral;
return;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static eAVLStatus
avlInsert(nsAVLNode*& aRootNode, nsAVLNode* aNewNode,
nsAVLNodeComparitor& aComparitor) {
eAVLStatus result=eAVL_unknown;
if(!aRootNode) {
aRootNode = aNewNode;
return eAVL_ok;
}
if(aNewNode==aRootNode->mValue) {
return eAVL_duplicate;
}
PRInt32 theCompareResult=aComparitor(aRootNode->mValue,aNewNode->mValue);
if(0 < theCompareResult) { //if(anItem<aRootNode->mValue)
result=avlInsert(aRootNode->mLeft,aNewNode,aComparitor);
if(eAVL_ok==result) {
switch(aRootNode->mSkew){
case eLeft:
avlRotateLeft(aRootNode);
result=eAVL_fail;
break;
case eRight:
aRootNode->mSkew=eNeutral;
result=eAVL_fail;
break;
case eNeutral:
aRootNode->mSkew=eLeft;
break;
} //switch
}//if
} //if
else {
result=avlInsert(aRootNode->mRight,aNewNode,aComparitor);
if(eAVL_ok==result) {
switch(aRootNode->mSkew){
case eLeft:
aRootNode->mSkew=eNeutral;
result=eAVL_fail;
break;
case eRight:
avlRotateRight(aRootNode);
result=eAVL_fail;
break;
case eNeutral:
aRootNode->mSkew=eRight;
break;
} //switch
}
} //if
return result;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static void
avlBalanceLeft(nsAVLNode*& aRootNode, PRBool& delOk){
nsAVLNode* ptr2;
nsAVLNode* ptr3;
eLean balnc2;
eLean balnc3;
switch(aRootNode->mSkew){
case eLeft:
ptr2=aRootNode->mLeft;
balnc2=ptr2->mSkew;
if(balnc2!=eRight) {
aRootNode->mLeft=ptr2->mRight;
ptr2->mRight=aRootNode;
if(balnc2==eNeutral){
aRootNode->mSkew=eLeft;
ptr2->mSkew=eRight;
delOk=PR_FALSE;
}
else{
aRootNode->mSkew=eNeutral;
ptr2->mSkew=eNeutral;
}
aRootNode=ptr2;
}
else{
ptr3=ptr2->mRight;
balnc3=ptr3->mSkew;
ptr2->mRight=ptr3->mLeft;
ptr3->mLeft=ptr2;
aRootNode->mLeft=ptr3->mRight;
ptr3->mRight=aRootNode;
if(balnc3==eRight) {
ptr2->mSkew=eLeft;
}
else {
ptr2->mSkew=eNeutral;
}
if(balnc3==eLeft) {
aRootNode->mSkew=eRight;
}
else {
aRootNode->mSkew=eNeutral;
}
aRootNode=ptr3;
ptr3->mSkew=eNeutral;
}
break;
case eRight:
aRootNode->mSkew=eNeutral;
break;
case eNeutral:
aRootNode->mSkew=eLeft;
delOk=PR_FALSE;
break;
}//switch
return;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static void
avlBalanceRight(nsAVLNode*& aRootNode, PRBool& delOk){
nsAVLNode* ptr2;
nsAVLNode* ptr3;
eLean balnc2;
eLean balnc3;
switch(aRootNode->mSkew){
case eLeft:
aRootNode->mSkew=eNeutral;
break;
case eRight:
ptr2=aRootNode->mRight;
balnc2=ptr2->mSkew;
if(balnc2!=eLeft) {
aRootNode->mRight=ptr2->mLeft;
ptr2->mLeft=aRootNode;
if(balnc2==eNeutral){
aRootNode->mSkew=eRight;
ptr2->mSkew=eLeft;
delOk=PR_FALSE;
}
else{
aRootNode->mSkew=eNeutral;
ptr2->mSkew=eNeutral;
}
aRootNode=ptr2;
}
else{
ptr3=ptr2->mLeft;
balnc3=ptr3->mSkew;
ptr2->mLeft=ptr3->mRight;
ptr3->mRight=ptr2;
aRootNode->mRight=ptr3->mLeft;
ptr3->mLeft=aRootNode;
if(balnc3==eLeft) {
ptr2->mSkew=eRight;
}
else {
ptr2->mSkew=eNeutral;
}
if(balnc3==eRight) {
aRootNode->mSkew=eLeft;
}
else {
aRootNode->mSkew=eNeutral;
}
aRootNode=ptr3;
ptr3->mSkew=eNeutral;
}
break;
case eNeutral:
aRootNode->mSkew=eRight;
delOk=PR_FALSE;
break;
}//switch
return;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static eAVLStatus
avlRemoveChildren(nsAVLNode*& aRootNode,nsAVLNode*& anotherNode, PRBool& delOk){
eAVLStatus result=eAVL_ok;
if(!anotherNode->mRight){
aRootNode->mValue=anotherNode->mValue; //swap
anotherNode=anotherNode->mLeft;
delOk=PR_TRUE;
}
else{
avlRemoveChildren(aRootNode,anotherNode->mRight,delOk);
if(delOk)
avlBalanceLeft(anotherNode,delOk);
}
return result;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static eAVLStatus
avlRemove(nsAVLNode*& aRootNode, void* anItem, PRBool& delOk,
nsAVLNodeComparitor& aComparitor){
eAVLStatus result=eAVL_ok;
if(!aRootNode)
delOk=PR_FALSE;
else {
PRInt32 cmp=aComparitor(anItem,aRootNode->mValue);
if(cmp<0){
avlRemove(aRootNode->mLeft,anItem,delOk,aComparitor);
if(delOk)
avlBalanceRight(aRootNode,delOk);
}
else if(cmp>0){
avlRemove(aRootNode->mRight,anItem,delOk,aComparitor);
if(delOk)
avlBalanceLeft(aRootNode,delOk);
}
else{ //they match...
nsAVLNode* temp=aRootNode;
if(!aRootNode->mRight) {
aRootNode=aRootNode->mLeft;
delOk=PR_TRUE;
delete temp;
}
else if(!aRootNode->mLeft) {
aRootNode=aRootNode->mRight;
delOk=PR_TRUE;
delete temp;
}
else {
avlRemoveChildren(aRootNode,aRootNode->mLeft,delOk);
if(delOk)
avlBalanceRight(aRootNode,delOk);
}
}
}
return result;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
eAVLStatus
nsAVLTree::AddItem(void* anItem){
eAVLStatus result=eAVL_ok;
nsAVLNode* theNewNode=new nsAVLNode(anItem);
result=avlInsert(mRoot,theNewNode,mComparitor);
if(eAVL_duplicate!=result)
mCount++;
else {
delete theNewNode;
}
return result;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
void* nsAVLTree::FindItem(void* aValue) const{
nsAVLNode* result=mRoot;
PRInt32 count=0;
while(result) {
count++;
PRInt32 cmp=mComparitor(aValue,result->mValue);
if(0==cmp) {
//we matched...
break;
}
else if(0>cmp){
//theNode was greater...
result=result->mLeft;
}
else {
//aValue is greater...
result=result->mRight;
}
}
if(result) {
return result->mValue;
}
return nsnull;
}
/**
*
* @update gess12/30/98
* @param
* @return
*/
eAVLStatus
nsAVLTree::RemoveItem(void* aValue){
PRBool delOk=PR_TRUE;
eAVLStatus result=avlRemove(mRoot,aValue,delOk,mComparitor);
if(eAVL_ok==result)
mCount--;
return result;
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
static void
avlForEachDepthFirst(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor){
if(aNode) {
avlForEachDepthFirst(aNode->mLeft,aFunctor);
avlForEachDepthFirst(aNode->mRight,aFunctor);
aFunctor(aNode->mValue);
}
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
void
nsAVLTree::ForEachDepthFirst(nsAVLNodeFunctor& aFunctor) const{
::avlForEachDepthFirst(mRoot,aFunctor);
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
static void
avlForEach(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor) {
if(aNode) {
avlForEach(aNode->mLeft,aFunctor);
aFunctor(aNode->mValue);
avlForEach(aNode->mRight,aFunctor);
}
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
void
nsAVLTree::ForEach(nsAVLNodeFunctor& aFunctor) const{
::avlForEach(mRoot,aFunctor);
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
static void*
avlFirstThat(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor) {
void* result=nsnull;
if(aNode) {
result = avlFirstThat(aNode->mLeft,aFunctor);
if (result) {
return result;
}
result = aFunctor(aNode->mValue);
if (result) {
return result;
}
result = avlFirstThat(aNode->mRight,aFunctor);
}
return result;
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
void*
nsAVLTree::FirstThat(nsAVLNodeFunctor& aFunctor) const{
return ::avlFirstThat(mRoot,aFunctor);
}

View File

@@ -0,0 +1,74 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsAVLTree_h___
#define nsAVLTree_h___
#include "nscore.h"
enum eAVLStatus {eAVL_unknown,eAVL_ok,eAVL_fail,eAVL_duplicate};
struct nsAVLNode;
/**
*
* @update gess12/26/98
* @param anObject1 is the first object to be compared
* @param anObject2 is the second object to be compared
* @return -1,0,1 if object1 is less, equal, greater than object2
*/
class NS_COM nsAVLNodeComparitor {
public:
virtual PRInt32 operator()(void* anItem1,void* anItem2)=0;
};
class NS_COM nsAVLNodeFunctor {
public:
virtual void* operator()(void* anItem)=0;
};
class NS_COM nsAVLTree {
public:
nsAVLTree(nsAVLNodeComparitor& aComparitor, nsAVLNodeFunctor* aDeallocator);
~nsAVLTree(void);
PRBool operator==(const nsAVLTree& aOther) const;
PRInt32 GetCount(void) const {return mCount;}
//main functions...
eAVLStatus AddItem(void* anItem);
eAVLStatus RemoveItem(void* anItem);
void* FindItem(void* anItem) const;
void ForEach(nsAVLNodeFunctor& aFunctor) const;
void ForEachDepthFirst(nsAVLNodeFunctor& aFunctor) const;
void* FirstThat(nsAVLNodeFunctor& aFunctor) const;
protected:
nsAVLNode* mRoot;
PRInt32 mCount;
nsAVLNodeComparitor& mComparitor;
nsAVLNodeFunctor* mDeallocator;
};
#endif /* nsAVLTree_h___ */

View File

@@ -1,28 +0,0 @@
#
# 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.
#
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = content base
include $(topsrcdir)/config/rules.mk

View File

@@ -1,28 +0,0 @@
#
# 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.
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src
include $(topsrcdir)/config/rules.mk

View File

@@ -1,22 +0,0 @@
#!nmake
#
# 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.
DEPTH=..\..\..
DIRS=public src
include <$(DEPTH)\config\rules.mak>

View File

@@ -1,31 +0,0 @@
#
# 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.
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = layout
EXPORTS = nsIPopupSetFrame.h
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -1,2 +0,0 @@
nsIPopupSetFrame.h

View File

@@ -1,26 +0,0 @@
#!nmake
#
# 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.
DEPTH=..\..\..\..
EXPORTS = \
nsIPopupSetFrame.h \
$(NULL)
MODULE=raptor
include <$(DEPTH)\config\rules.mak>

View File

@@ -1,52 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsIMenuParent_h___
#define nsIMenuParent_h___
// {D407BF61-3EFA-11d3-97FA-00400553EEF0}
#define NS_IMENUPARENT_IID \
{ 0xd407bf61, 0x3efa, 0x11d3, { 0x97, 0xfa, 0x0, 0x40, 0x5, 0x53, 0xee, 0xf0 } }
class nsIMenuFrame;
class nsIMenuParent : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IMENUPARENT_IID; return iid; }
NS_IMETHOD SetCurrentMenuItem(nsIMenuFrame* aMenuItem) = 0;
NS_IMETHOD GetNextMenuItem(nsIMenuFrame* aStart, nsIMenuFrame** aResult) = 0;
NS_IMETHOD GetPreviousMenuItem(nsIMenuFrame* aStart, nsIMenuFrame** aResult) = 0;
NS_IMETHOD SetActive(PRBool aActiveFlag) = 0;
NS_IMETHOD GetIsActive(PRBool& isActive) = 0;
NS_IMETHOD GetWidget(nsIWidget **aWidget) = 0;
NS_IMETHOD IsMenuBar(PRBool& isMenuBar) = 0;
NS_IMETHOD DismissChain() = 0;
NS_IMETHOD HideChain() = 0;
NS_IMETHOD CreateDismissalListener() = 0;
};
#endif

View File

@@ -1,47 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsIPopupSetFrame_h___
#define nsIPopupSetFrame_h___
// {E2D804A1-50CA-11d3-BF87-00105A1B0627}
#define NS_IPOPUPSETFRAME_IID \
{ 0xe2d804a1, 0x50ca, 0x11d3, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
class nsIFrame;
class nsIContent;
#include "nsString.h"
class nsIPopupSetFrame : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IPOPUPSETFRAME_IID; return iid; }
NS_IMETHOD CreatePopup(nsIFrame* aElementFrame, nsIContent* aPopupContent,
PRInt32 aXPos, PRInt32 aYPos,
const nsString& aPopupType, const nsString& anAnchorAlignment,
const nsString& aPopupAlignment) = 0;
NS_IMETHOD HidePopup() = 0;
NS_IMETHOD DestroyPopup() = 0;
};
#endif

View File

@@ -1,85 +0,0 @@
#
# 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.
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = layout
LIBRARY_NAME = raptorxulbase_s
CPPSRCS = \
nsFrameNavigator.cpp \
nsSplitterFrame.cpp \
nsGrippyFrame.cpp \
nsTabFrame.cpp \
nsDeckFrame.cpp \
nsBoxFrame.cpp \
nsProgressMeterFrame.cpp \
nsTitledButtonFrame.cpp \
nsToolbarFrame.cpp \
nsToolbarDragListener.cpp \
nsToolboxFrame.cpp \
nsTreeOuterFrame.cpp \
nsTreeFrame.cpp \
nsTreeRowGroupFrame.cpp \
nsTreeIndentationFrame.cpp \
nsTreeCellFrame.cpp \
nsTreeRowFrame.cpp \
nsTreeTwistyListener.cpp \
nsSpinnerFrame.cpp \
nsScrollbarFrame.cpp \
nsScrollbarButtonFrame.cpp \
nsSliderFrame.cpp \
nsColorPickerFrame.cpp \
nsStdColorPicker.cpp \
nsFontPickerFrame.cpp \
nsToolbarItemFrame.cpp \
nsMenuPopupFrame.cpp \
nsMenuFrame.cpp \
nsMenuBarFrame.cpp \
nsMenuBarListener.cpp \
nsMenuDismissalListener.cpp \
nsPopupSetFrame.cpp \
nsRepeatService.cpp \
$(NULL)
include $(topsrcdir)/config/config.mk
# we don't want the shared lib, but we want to force the creation of a static lib.
override NO_SHARED_LIB=1
override NO_STATIC_LIB=
include $(topsrcdir)/config/rules.mk
DEFINES += -D_IMPL_NS_HTML
LOCAL_INCLUDES = \
-I$(srcdir)/../../../base/src \
-I$(srcdir)/../../../html/table/src \
-I$(srcdir)/../../../html/style/src \
-I$(srcdir)/../../../html/base/src \
-I$(srcdir)/../../../html/forms/src \
-I$(srcdir)/../../content/src \
-I$(srcdir)/../../../html/content/src \
-I$(srcdir)/../../../xml/content/src \
-I$(srcdir)/../../../base/public \
$(NULL)

View File

@@ -1,123 +0,0 @@
#!nmake
#
# 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.
DEPTH=..\..\..\..
LIBRARY_NAME=raptorxulbase_s
MODULE=raptor
REQUIRES=xpcom raptor pref
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
CPPSRCS= \
nsFrameNavigator.cpp \
nsRepeatService.cpp \
nsToolbarDragListener.cpp \
nsToolbarItemFrame.cpp \
nsSplitterFrame.cpp \
nsGrippyFrame.cpp \
nsTabFrame.cpp \
nsDeckFrame.cpp \
nsBoxFrame.cpp \
nsProgressMeterFrame.cpp \
nsTitledButtonFrame.cpp \
nsToolboxFrame.cpp \
nsToolbarFrame.cpp \
nsTreeOuterFrame.cpp \
nsTreeFrame.cpp \
nsTreeRowGroupFrame.cpp \
nsTreeRowFrame.cpp \
nsTreeIndentationFrame.cpp \
nsTreeCellFrame.cpp \
nsTreeTwistyListener.cpp \
nsSpinnerFrame.cpp \
nsScrollbarFrame.cpp \
nsScrollbarButtonFrame.cpp \
nsSliderFrame.cpp \
nsColorPickerFrame.cpp \
nsStdColorPicker.cpp \
nsFontPickerFrame.cpp \
nsMenuPopupFrame.cpp \
nsMenuFrame.cpp \
nsMenuBarFrame.cpp \
nsMenuBarListener.cpp \
nsMenuDismissalListener.cpp \
nsPopupSetFrame.cpp \
$(NULL)
CPP_OBJS= \
.\$(OBJDIR)\nsFrameNavigator.obj \
.\$(OBJDIR)\nsRepeatService.obj \
.\$(OBJDIR)\nsToolbarDragListener.obj \
.\$(OBJDIR)\nsToolbarItemFrame.obj \
.\$(OBJDIR)\nsGrippyFrame.obj \
.\$(OBJDIR)\nsSplitterFrame.obj \
.\$(OBJDIR)\nsTabFrame.obj \
.\$(OBJDIR)\nsDeckFrame.obj \
.\$(OBJDIR)\nsBoxFrame.obj \
.\$(OBJDIR)\nsProgressMeterFrame.obj \
.\$(OBJDIR)\nsTitledButtonFrame.obj \
.\$(OBJDIR)\nsToolboxFrame.obj \
.\$(OBJDIR)\nsToolbarFrame.obj \
.\$(OBJDIR)\nsTreeOuterFrame.obj \
.\$(OBJDIR)\nsTreeFrame.obj \
.\$(OBJDIR)\nsTreeRowFrame.obj \
.\$(OBJDIR)\nsTreeRowGroupFrame.obj \
.\$(OBJDIR)\nsTreeIndentationFrame.obj \
.\$(OBJDIR)\nsTreeCellFrame.obj \
.\$(OBJDIR)\nsTreeTwistyListener.obj \
.\$(OBJDIR)\nsSpinnerFrame.obj \
.\$(OBJDIR)\nsScrollbarFrame.obj \
.\$(OBJDIR)\nsScrollbarButtonFrame.obj \
.\$(OBJDIR)\nsSliderFrame.obj \
.\$(OBJDIR)\nsColorPickerFrame.obj \
.\$(OBJDIR)\nsStdColorPicker.obj \
.\$(OBJDIR)\nsFontPickerFrame.obj \
.\$(OBJDIR)\nsMenuPopupFrame.obj \
.\$(OBJDIR)\nsMenuFrame.obj \
.\$(OBJDIR)\nsMenuBarFrame.obj \
.\$(OBJDIR)\nsMenuBarListener.obj \
.\$(OBJDIR)\nsMenuDismissalListener.obj \
.\$(OBJDIR)\nsPopupSetFrame.obj \
$(NULL)
EXPORTS = \
$(NULL)
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\js \
-I..\..\..\html\style\src -I..\..\..\html\base\src -I$(PUBLIC)\dom \
-I..\..\..\html\document\src \
-I..\..\..\html\content\src \
-I..\..\..\html\table\src \
-I..\..\content\src \
-I..\..\..\html\forms\src \
-I$(PUBLIC)\netlib -I..\..\..\base\src -I$(PUBLIC)\pref \
-I..\..\..\xml\content\src \
-I..\..\..\base\public
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
include <$(DEPTH)\config\rules.mak>
libs:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

File diff suppressed because it is too large Load Diff

View File

@@ -1,196 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
/**
Eric D Vaughan
nsBoxFrame is a frame that can lay its children out either vertically or horizontally.
It lays them out according to a min max or preferred size.
**/
#ifndef nsBoxFrame_h___
#define nsBoxFrame_h___
#include "nsCOMPtr.h"
#include "nsHTMLContainerFrame.h"
#include "nsIBox.h"
#include "nsISpaceManager.h"
class nsBoxFrameInner;
class nsBoxDebugInner;
class nsHTMLReflowCommand;
class nsCalculatedBoxInfo : public nsBoxInfo {
public:
nsSize calculatedSize;
PRBool prefWidthIntrinsic;
PRBool prefHeightIntrinsic;
PRBool sizeValid;
PRBool needsReflow;
PRBool needsRecalc;
PRBool collapsed;
PRBool isIncremental;
nsCalculatedBoxInfo();
nsCalculatedBoxInfo(const nsBoxInfo& aInfo);
virtual void clear();
};
class nsBoxFrame : public nsHTMLContainerFrame, public nsIBox
{
public:
friend nsresult NS_NewBoxFrame(nsIFrame** aNewFrame, PRUint32 aFlags = 0);
// gets the rect inside our border and debug border. If you wish to paint inside a box
// call this method to get the rect so you don't draw on the debug border or outer border.
virtual void GetInnerRect(nsRect& aInner);
NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext,
const nsPoint& aPoint,
nsIFrame** aFrame);
NS_IMETHOD GetCursor(nsIPresContext& aPresContext,
nsPoint& aPoint,
PRInt32& aCursor);
// nsIBox methods
NS_IMETHOD GetBoxInfo(nsIPresContext& aPresContext, const nsHTMLReflowState& aReflowState, nsBoxInfo& aSize);
NS_IMETHOD Dirty(nsIPresContext& aPresContext, const nsHTMLReflowState& aReflowState, nsIFrame*& aIncrementalChild);
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD DidReflow(nsIPresContext& aPresContext,
nsDidReflowStatus aStatus);
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* asPrevInFlow);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint);
NS_IMETHOD Paint ( nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD AppendFrames(nsIPresContext& aPresContext,
nsIPresShell& aPresShell,
nsIAtom* aListName,
nsIFrame* aFrameList);
NS_IMETHOD InsertFrames(nsIPresContext& aPresContext,
nsIPresShell& aPresShell,
nsIAtom* aListName,
nsIFrame* aPrevFrame,
nsIFrame* aFrameList);
NS_IMETHOD RemoveFrame(nsIPresContext& aPresContext,
nsIPresShell& aPresShell,
nsIAtom* aListName,
nsIFrame* aOldFrame);
NS_IMETHOD GetFrameName(nsString& aResult) const;
virtual PRBool IsHorizontal() const { return mHorizontal; }
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
virtual ~nsBoxFrame();
virtual void GetChildBoxInfo(PRInt32 aIndex, nsBoxInfo& aSize);
virtual void SetChildNeedsRecalc(PRInt32 aIndex, PRBool aRecalc);
// Paint one child frame
virtual void PaintChild(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsIFrame* aFrame,
nsFramePaintLayer aWhichLayer);
protected:
nsBoxFrame(PRUint32 aFlags = 0);
virtual void GetRedefinedMinPrefMax(nsIPresContext& aPresContext, nsIFrame* aFrame, nsCalculatedBoxInfo& aSize);
virtual nsresult GetChildBoxInfo(nsIPresContext& aPresContext, const nsHTMLReflowState& aReflowState, nsIFrame* aFrame, nsCalculatedBoxInfo& aSize);
virtual nsresult FlowChildren(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus,
nsRect& availableSize);
virtual nsresult FlowChildAt(nsIFrame* frame,
nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus,
nsCalculatedBoxInfo& aInfo,
PRBool& needsRedraw,
nsString& aReason);
virtual nsresult PlaceChildren(nsIPresContext& aPresContext, nsRect& boxRect);
virtual void ChildResized(nsIFrame* aFrame, nsHTMLReflowMetrics& aDesiredSize, nsRect& aRect, nsCalculatedBoxInfo& aInfo, PRBool* aResized, nscoord& aChangedIndex, PRBool& aFinished, nscoord aIndex, nsString& aReason);
virtual void LayoutChildrenInRect(nsRect& size);
virtual void AddChildSize(nsBoxInfo& aInfo, nsBoxInfo& aChildInfo);
virtual void BoundsCheck(const nsBoxInfo& aBoxInfo, nsRect& aRect);
virtual void InvalidateChildren();
virtual void AddSize(const nsSize& a, nsSize& b, PRBool largest);
virtual PRIntn GetSkipSides() const { return 0; }
virtual void GetInset(nsMargin& margin);
virtual void CollapseChild(nsIPresContext& aPresContext, nsIFrame* frame, PRBool hide);
nsresult GenerateDirtyReflowCommand(nsIPresContext& aPresContext,
nsIPresShell& aPresShell);
PRBool mHorizontal;
nsCalculatedBoxInfo mSprings[100];
nscoord mSpringCount;
private:
friend class nsBoxFrameInner;
friend class nsBoxDebugInner;
nsBoxFrameInner* mInner;
}; // class nsBoxFrame
#endif

View File

@@ -1,27 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
// 1936f892-1dd2-11b2-aba4-bd254241f938
#define NS_DEFCOLORPICKER_CID \
{ 0x1936f892, 0x1dd2, 0x11b2, \
{0xab, 0xa4, 0xbd, 0x25, 0x42, 0x41, 0xf9, 0x38} }

View File

@@ -1,230 +0,0 @@
/* -*- 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 "nsColorPickerFrame.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"
#include "prtypes.h"
#include "nsIAtom.h"
#include "nsHTMLAtoms.h"
#include "nsIPresContext.h"
#include "nsIStyleContext.h"
#include "nsCSSRendering.h"
#include "nsINameSpaceManager.h"
#include "nsColor.h"
#include "nsIServiceManager.h"
#include "nsStdColorPicker.h"
#include "nsColorPickerCID.h"
//
// NS_NewColorPickerFrame
//
// Wrapper for creating a new color picker
//
nsresult
NS_NewColorPickerFrame(nsIFrame** aNewFrame)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsColorPickerFrame* it = new nsColorPickerFrame;
if ( !it )
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = it;
return NS_OK;
}
// static NS_DEFINE_IID(kDefColorPickerCID, NS_DEFCOLORPICKER_CID);
//
// nsColorPickerFrame cntr
//
nsColorPickerFrame::nsColorPickerFrame()
{
}
nsColorPickerFrame::~nsColorPickerFrame()
{
delete mColorPicker;
}
NS_IMETHODIMP
nsColorPickerFrame::Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsLeafFrame::Init(aPresContext, aContent, aParent, aContext,
aPrevInFlow);
nsAutoString type;
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, type);
if (type.EqualsIgnoreCase("swatch") || type.Equals(""))
{
mColorPicker = new nsStdColorPicker();
mColorPicker->Init(mContent);
}
return rv;
}
NS_IMETHODIMP
nsColorPickerFrame::HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
aEventStatus = nsEventStatus_eConsumeDoDefault;
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN)
HandleMouseDownEvent(aPresContext, aEvent, aEventStatus);
return NS_OK;
}
nsresult
nsColorPickerFrame::HandleMouseDownEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
int x,y;
char *color;
// figure out what color we just picked
#ifdef DEBUG_pavlov
printf("got mouse down.. x = %i, y = %i\n", aEvent->refPoint.x, aEvent->refPoint.y);
#endif
x = aEvent->refPoint.x;
y = aEvent->refPoint.y;
nsCOMPtr<nsIDOMElement> node( do_QueryInterface(mContent) );
nsresult rv = mColorPicker->GetColor(x, y, &color);
if (NS_FAILED(rv))
node->RemoveAttribute("color");
else
node->SetAttribute("color", color);
return NS_OK;
}
//
// Paint
//
//
NS_METHOD
nsColorPickerFrame::Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)
{
float p2t;
aPresContext.GetScaledPixelsToTwips(&p2t);
const nsStyleDisplay* disp = (const nsStyleDisplay*)
mStyleContext->GetStyleData(eStyleStruct_Display);
// if we aren't visible then we are done.
if (!disp->mVisible)
return NS_OK;
// if we are visible then tell our superclass to paint
nsLeafFrame::Paint(aPresContext, aRenderingContext, aDirtyRect,
aWhichLayer);
// get our border
const nsStyleSpacing* spacing = (const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
nsMargin border(0,0,0,0);
spacing->CalcBorderFor(this, border);
/*
const nsStyleColor* colorStyle = (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
nscolor color = colorStyle->mColor;
*/
aRenderingContext.PushState();
// set the clip region
PRInt32 width, height;
mColorPicker->GetSize(&width, &height);
nsRect rect(0, 0, PRInt32(width*p2t), PRInt32(height*p2t));
PRBool clipState;
// Clip so we don't render outside the inner rect
aRenderingContext.SetClipRect(rect, nsClipCombine_kIntersect, clipState);
// call the color picker's paint method
mColorPicker->Paint(&aPresContext, &aRenderingContext);
aRenderingContext.PopState(clipState);
return NS_OK;
}
//
// GetDesiredSize
//
// For now, be as big as CSS wants us to be, or some small default size.
//
void
nsColorPickerFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize)
{
float p2t;
aPresContext->GetScaledPixelsToTwips(&p2t);
// if the width is set use it
if (NS_INTRINSICSIZE != aReflowState.mComputedWidth)
aDesiredSize.width = aReflowState.mComputedWidth;
else
aDesiredSize.width = -1;
// if the height is set use it
if (NS_INTRINSICSIZE != aReflowState.mComputedHeight)
aDesiredSize.height = aReflowState.mComputedHeight;
else
aDesiredSize.height = -1;
mColorPicker->SetSize((aDesiredSize.width == -1) ? -1 : PRInt32(aDesiredSize.width/p2t),
(aDesiredSize.height == -1) ? -1 : PRInt32(aDesiredSize.height/p2t));
int width, height;
mColorPicker->GetSize(&width, &height);
aDesiredSize.width = nscoord(width * p2t);
aDesiredSize.height = nscoord(height * p2t);
aDesiredSize.ascent = nscoord(height * p2t);
aDesiredSize.descent = 0;
} // GetDesiredSize

View File

@@ -1,81 +0,0 @@
/* -*- 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.
*/
//
// nsColorPickerFrame
//
#ifndef nsColorPickerFrame_h__
#define nsColorPickerFrame_h__
#include "nsLeafFrame.h"
#include "prtypes.h"
#include "nsIAtom.h"
#include "nsCOMPtr.h"
#include "nsIColorPicker.h"
class nsString;
nsresult NS_NewColorPickerFrame(nsIFrame** aResult) ;
class nsColorPickerFrame : public nsLeafFrame
{
public:
nsColorPickerFrame();
virtual ~nsColorPickerFrame();
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow);
#ifdef DEBUG
NS_IMETHOD GetFrameName(nsString& aResult) const {
return MakeFrameName("ColorPickerFrame", aResult);
}
#endif
// nsIFrame overrides
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
nsresult HandleMouseDownEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
protected:
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize) ;
private:
nsIColorPicker *mColorPicker;
}; // class nsColorPickerFrame
#endif

View File

@@ -1,363 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
//
// Eric Vaughan
// Netscape Communications
//
// See documentation in associated header file
//
#include "nsDeckFrame.h"
#include "nsIStyleContext.h"
#include "nsIPresContext.h"
#include "nsIContent.h"
#include "nsCOMPtr.h"
#include "nsHTMLIIDs.h"
#include "nsUnitConversion.h"
#include "nsINameSpaceManager.h"
#include "nsXULAtoms.h"
#include "nsHTMLAtoms.h"
#include "nsIReflowCommand.h"
#include "nsHTMLParts.h"
#include "nsIPresShell.h"
#include "nsStyleChangeList.h"
#include "nsCSSRendering.h"
#include "nsIViewManager.h"
nsresult
NS_NewDeckFrame ( nsIFrame** aNewFrame )
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsDeckFrame* it = new nsDeckFrame;
if (nsnull == it)
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = it;
return NS_OK;
} // NS_NewDeckFrame
NS_IMETHODIMP
nsDeckFrame::Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
// Get the element's tag
nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
//CreateViewForFrame(aPresContext,this,aContext,PR_TRUE);
return rv;
}
NS_IMETHODIMP
nsDeckFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint)
{
nsresult rv = nsBoxFrame::AttributeChanged(aPresContext, aChild,
aNameSpaceID, aAttribute, aHint);
// if the index changed hide the old element and make the now element visible
if (aAttribute == nsHTMLAtoms::index) {
/*
nsCOMPtr<nsIPresShell> shell;
aPresContext->GetShell(getter_AddRefs(shell));
nsCOMPtr<nsIReflowCommand> reflowCmd;
rv = NS_NewHTMLReflowCommand(getter_AddRefs(reflowCmd), this,
nsIReflowCommand::StyleChanged);
if (NS_SUCCEEDED(rv))
shell->AppendReflowCommand(reflowCmd);
*/
Invalidate(aPresContext, nsRect(0,0,mRect.width,mRect.height), PR_FALSE);
int index = 0;
// get the index attribute
nsAutoString value;
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::index, value))
{
PRInt32 error;
// convert it to an integer
index = value.ToInteger(&error);
}
nsIFrame* childFrame = mFrames.FirstChild();
nscoord count = 0;
while (nsnull != childFrame)
{
// make collapsed children not show up
if (index != count)
CollapseChild(*aPresContext, childFrame, PR_TRUE);
else
CollapseChild(*aPresContext, childFrame, PR_FALSE);
rv = childFrame->GetNextSibling(&childFrame);
NS_ASSERTION(rv == NS_OK,"failed to get next child");
count++;
}
}
if (NS_OK != rv) {
return rv;
}
return NS_OK;
}
nsIFrame*
nsDeckFrame::GetSelectedFrame()
{
// ok we want to paint only the child that as at the given index
// default index is 0
int index = 0;
// get the index attribute
nsAutoString value;
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::index, value))
{
PRInt32 error;
// convert it to an integer
index = value.ToInteger(&error);
}
// get the child at that index.
nsIFrame* childFrame = mFrames.FrameAt(index);
return childFrame;
}
NS_IMETHODIMP
nsDeckFrame::Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)
{
// if a tab is hidden all its children are too.
const nsStyleDisplay* disp = (const nsStyleDisplay*)
mStyleContext->GetStyleData(eStyleStruct_Display);
if (!disp->mVisible)
return NS_OK;
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
if (disp->mVisible && mRect.width && mRect.height) {
// Paint our background and border
PRIntn skipSides = GetSkipSides();
const nsStyleColor* color = (const nsStyleColor*)
mStyleContext->GetStyleData(eStyleStruct_Color);
const nsStyleSpacing* spacing = (const nsStyleSpacing*)
mStyleContext->GetStyleData(eStyleStruct_Spacing);
nsRect rect(0, 0, mRect.width, mRect.height);
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this,
aDirtyRect, rect, *color, *spacing, 0, 0);
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,
aDirtyRect, rect, *spacing, mStyleContext, skipSides);
}
}
nsIFrame* frame = GetSelectedFrame();
if (frame != nsnull)
PaintChild(aPresContext, aRenderingContext, aDirtyRect, frame, aWhichLayer);
return NS_OK;
}
NS_IMETHODIMP nsDeckFrame::GetFrameForPoint(nsIPresContext* aPresContext,
const nsPoint& aPoint,
nsIFrame** aFrame)
{
// if its not in our child just return us.
*aFrame = this;
// get the selected frame and see if the point is in it.
nsIFrame* selectedFrame = GetSelectedFrame();
if (nsnull != selectedFrame)
{
nsRect childRect;
selectedFrame->GetRect(childRect);
if (childRect.Contains(aPoint)) {
// adjust the point
nsPoint p = aPoint;
p.x -= childRect.x;
p.y -= childRect.y;
return selectedFrame->GetFrameForPoint(aPresContext, p, aFrame);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsDeckFrame::SetInitialChildList(nsIPresContext& aPresContext,
nsIAtom* aListName,
nsIFrame* aChildList)
{
nsresult r = nsBoxFrame::SetInitialChildList(aPresContext, aListName, aChildList);
return r;
}
void
nsDeckFrame::AddChildSize(nsBoxInfo& aInfo, nsBoxInfo& aChildInfo)
{
// largest preferred size
if (aChildInfo.prefSize.width > aInfo.prefSize.width)
aInfo.prefSize.width = aChildInfo.prefSize.width;
if (aChildInfo.prefSize.height > aInfo.prefSize.height)
aInfo.prefSize.height = aChildInfo.prefSize.height;
// largest min size
if (aChildInfo.minSize.width > aInfo.minSize.width)
aInfo.minSize.width = aChildInfo.minSize.width;
if (aChildInfo.minSize.height > aInfo.minSize.height)
aInfo.minSize.height = aChildInfo.minSize.height;
// smallest max size
if (aChildInfo.maxSize.width < aInfo.maxSize.width)
aInfo.maxSize.width = aChildInfo.maxSize.width;
if (aChildInfo.maxSize.height < aInfo.maxSize.height)
aInfo.maxSize.height = aChildInfo.maxSize.height;
}
nsresult
nsDeckFrame::PlaceChildren(nsIPresContext& aPresContext, nsRect& boxRect)
{
// ------- set the childs positions ---------
nsIFrame* childFrame = mFrames.FirstChild();
nscoord count = 0;
while (nsnull != childFrame)
{
nsresult rv;
// make collapsed children not show up
if (mSprings[count].collapsed) {
//nsRect rect(0,0,0,0);
//childFrame->GetRect(rect);
//if (rect.width > 0 || rect.height > 0) {
// childFrame->SizeTo(0,0);
CollapseChild(aPresContext, childFrame, PR_TRUE);
//}
} else {
childFrame->MoveTo(&aPresContext, boxRect.x, boxRect.y);
}
rv = childFrame->GetNextSibling(&childFrame);
NS_ASSERTION(rv == NS_OK,"failed to get next child");
count++;
}
return NS_OK;
}
NS_IMETHODIMP
nsDeckFrame::DidReflow(nsIPresContext& aPresContext,
nsDidReflowStatus aStatus)
{
int index = 0;
// get the index attribute
nsAutoString value;
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::index, value))
{
PRInt32 error;
// convert it to an integer
index = value.ToInteger(&error);
}
nsresult rv = nsBoxFrame::DidReflow(aPresContext, aStatus);
NS_ASSERTION(rv == NS_OK,"DidReflow failed");
nsIFrame* childFrame = mFrames.FirstChild();
nscoord count = 0;
while (nsnull != childFrame)
{
// make collapsed children not show up
if (index != count)
CollapseChild(aPresContext, childFrame, PR_TRUE);
else
CollapseChild(aPresContext, childFrame, PR_FALSE);
rv = childFrame->GetNextSibling(&childFrame);
NS_ASSERTION(rv == NS_OK,"failed to get next child");
count++;
}
return rv;
}
void
nsDeckFrame::ChildResized(nsIFrame* aFrame, nsHTMLReflowMetrics& aDesiredSize, nsRect& aRect, nsCalculatedBoxInfo& aInfo, PRBool* aResized, nscoord& aChangedIndex, PRBool& aFinished, nscoord aIndex, nsString& aReason)
{
if (aDesiredSize.width > aRect.width) {
aRect.width = aDesiredSize.width;
InvalidateChildren();
LayoutChildrenInRect(aRect);
aReason = "child's width got bigger";
aChangedIndex = aIndex;
aFinished = PR_FALSE;
} else if (aDesiredSize.height > aRect.height) {
aRect.height = aDesiredSize.height;
InvalidateChildren();
LayoutChildrenInRect(aRect);
aReason = "child's height got bigger";
aChangedIndex = aIndex;
aFinished = PR_FALSE;
}
}
void
nsDeckFrame::LayoutChildrenInRect(nsRect& size)
{
for (int i=0; i<mSpringCount; i++) {
mSprings[i].calculatedSize.width = size.width;
mSprings[i].calculatedSize.height = size.height;
mSprings[i].sizeValid = PR_TRUE;
}
}

View File

@@ -1,93 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
/**
Eric D Vaughan
A frame that can have multiple children. Only one child may be displayed at one time. So the
can be flipped though like a deck of cards.
**/
#ifndef nsDeckFrame_h___
#define nsDeckFrame_h___
#include "nsBoxFrame.h"
class nsDeckFrame : public nsBoxFrame
{
public:
friend nsresult NS_NewDeckFrame(nsIFrame** aNewFrame);
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* asPrevInFlow);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint);
NS_IMETHOD DidReflow(nsIPresContext& aPresContext,
nsDidReflowStatus aStatus);
NS_IMETHOD Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
NS_IMETHOD SetInitialChildList(nsIPresContext& aPresContext,
nsIAtom* aListName,
nsIFrame* aChildList);
NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext,
const nsPoint& aPoint,
nsIFrame** aFrame);
virtual PRIntn GetSkipSides() const { return 0; }
protected:
virtual nsIFrame* GetSelectedFrame();
virtual nsresult PlaceChildren(nsIPresContext& aPresContext, nsRect& boxRect);
virtual void ChildResized(nsIFrame* aFrame, nsHTMLReflowMetrics& aDesiredSize, nsRect& aRect, nsCalculatedBoxInfo& aInfo, PRBool* aResized, nscoord& aChangedIndex, PRBool& aFinished, nscoord aIndex, nsString& aReason);
virtual void LayoutChildrenInRect(nsRect& size);
virtual void AddChildSize(nsBoxInfo& aInfo, nsBoxInfo& aChildInfo);
private:
nsIFrame* mSelected;
}; // class nsDeckFrame
#endif

View File

@@ -1,111 +0,0 @@
/* -*- 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 "nsFontPickerFrame.h"
#include "nsIContent.h"
#include "prtypes.h"
#include "nsIAtom.h"
#include "nsIPresContext.h"
#include "nsIStyleContext.h"
#include "nsCSSRendering.h"
#include "nsINameSpaceManager.h"
//
// NS_NewFontPickerFrame
//
// Wrapper for creating a new font picker
//
nsresult
NS_NewFontPickerFrame(nsIFrame** aNewFrame)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsFontPickerFrame* it = new nsFontPickerFrame;
if ( !it )
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = it;
return NS_OK;
}
//
// nsFontPickerFrame cntr
//
nsFontPickerFrame::nsFontPickerFrame()
{
} // cntr
//
// Paint
//
// Overidden to handle ???
//
NS_METHOD
nsFontPickerFrame::Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)
{
return nsLeafFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
}
//
// GetDesiredSize
//
// For now, be as big as CSS wants us to be, or some small default size.
//
void
nsFontPickerFrame :: GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredLayoutSize)
{
const int CSS_NOTSET = -1;
nsSize styleSize;
if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedWidth) {
styleSize.width = aReflowState.mComputedWidth;
}
else {
styleSize.width = CSS_NOTSET;
}
if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedHeight) {
styleSize.height = aReflowState.mComputedHeight;
}
else {
styleSize.height = CSS_NOTSET;
}
// subclasses should always override this method, but if not and no css, make it small
aDesiredLayoutSize.width = (styleSize.width > CSS_NOTSET) ? styleSize.width : 200;
aDesiredLayoutSize.height = (styleSize.height > CSS_NOTSET) ? styleSize.height : 200;
aDesiredLayoutSize.ascent = aDesiredLayoutSize.height;
aDesiredLayoutSize.descent = 0;
if (aDesiredLayoutSize.maxElementSize) {
aDesiredLayoutSize.maxElementSize->width = aDesiredLayoutSize.width;
aDesiredLayoutSize.maxElementSize->height = aDesiredLayoutSize.height;
}
} // GetDesiredSize

View File

@@ -1,63 +0,0 @@
/* -*- 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.
*/
//
// nsFontPickerFrame
//
#ifndef nsFontPickerFrame_h__
#define nsFontPickerFrame_h__
#include "nsLeafFrame.h"
#include "prtypes.h"
#include "nsIAtom.h"
#include "nsCOMPtr.h"
class nsString;
nsresult NS_NewFontPickerFrame(nsIFrame** aResult) ;
class nsFontPickerFrame : public nsLeafFrame
{
public:
nsFontPickerFrame();
#ifdef DEBUG
NS_IMETHOD GetFrameName(nsString& aResult) const {
return MakeFrameName("FontPickerFrame", aResult);
}
#endif
// nsIFrame overrides
NS_IMETHOD Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
protected:
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize) ;
}; // class nsFontPickerFrame
#endif

View File

@@ -1,127 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
//
// Eric Vaughan
// Netscape Communications
//
// See documentation in associated header file
//
#include "nsFrameNavigator.h"
#include "nsCOMPtr.h"
#include "nsIContent.h"
nsIAtom*
nsFrameNavigator::GetTag(nsIFrame* frame)
{
nsCOMPtr<nsIContent> content;
frame->GetContent(getter_AddRefs(content));
if (content) {
nsIAtom* atom = nsnull;
content->GetTag(atom);
return atom;
}
return nsnull;
}
nsIFrame*
nsFrameNavigator::GetChildBeforeAfter(nsIFrame* start, PRBool before)
{
nsIFrame* parent = nsnull;
start->GetParent(&parent);
PRInt32 index = IndexOf(parent,start);
PRInt32 count = CountFrames(parent);
if (index == -1)
return nsnull;
if (before) {
if (index == 0) {
return nsnull;
}
return GetChildAt(parent, index-1);
}
if (index == count-1)
return nsnull;
return GetChildAt(parent, index+1);
}
PRInt32
nsFrameNavigator::IndexOf(nsIFrame* parent, nsIFrame* child)
{
PRInt32 count = 0;
nsIFrame* childFrame;
parent->FirstChild(nsnull, &childFrame);
while (nsnull != childFrame)
{
if (childFrame == child)
return count;
nsresult rv = childFrame->GetNextSibling(&childFrame);
NS_ASSERTION(rv == NS_OK,"failed to get next child");
count++;
}
return -1;
}
PRInt32
nsFrameNavigator::CountFrames(nsIFrame* aFrame)
{
PRInt32 count = 0;
nsIFrame* childFrame;
aFrame->FirstChild(nsnull, &childFrame);
while (nsnull != childFrame)
{
nsresult rv = childFrame->GetNextSibling(&childFrame);
NS_ASSERTION(rv == NS_OK,"failed to get next child");
count++;
}
return count;
}
nsIFrame*
nsFrameNavigator::GetChildAt(nsIFrame* parent, PRInt32 index)
{
PRInt32 count = 0;
nsIFrame* childFrame;
parent->FirstChild(nsnull, &childFrame);
while (nsnull != childFrame)
{
if (count == index)
return childFrame;
nsresult rv = childFrame->GetNextSibling(&childFrame);
NS_ASSERTION(rv == NS_OK,"failed to get next child");
count++;
}
return nsnull;
}

View File

@@ -1,47 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
/**
Eric D Vaughan
This class lays out its children either vertically or horizontally
**/
#ifndef nsGrippyFrame_h___
#define nsGrippyFrame_h___
#include "nsIFrame.h"
class nsFrameNavigator
{
public:
static nsIFrame* GetChildBeforeAfter(nsIFrame* start, PRBool before);
static nsIFrame* GetChildAt(nsIFrame* parent, PRInt32 index);
static PRInt32 IndexOf(nsIFrame* parent, nsIFrame* child);
static PRInt32 CountFrames(nsIFrame* aFrame);
static nsIAtom* GetTag(nsIFrame* frame);
};
#endif

View File

@@ -1,240 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
//
// Eric Vaughan
// Netscape Communications
//
// See documentation in associated header file
//
#include "nsGrippyFrame.h"
#include "nsScrollbarButtonFrame.h"
#include "nsIStyleContext.h"
#include "nsIPresContext.h"
#include "nsIContent.h"
#include "nsCOMPtr.h"
#include "nsHTMLIIDs.h"
#include "nsUnitConversion.h"
#include "nsINameSpaceManager.h"
#include "nsHTMLAtoms.h"
#include "nsXULAtoms.h"
#include "nsIReflowCommand.h"
//#include "nsSliderFrame.h"
#include "nsIDOMElement.h"
#include "nsIDOMDocument.h"
#include "nsDocument.h"
#include "nsHTMLParts.h"
#include "nsIPresShell.h"
#include "nsIView.h"
#include "nsIViewManager.h"
#include "nsHTMLContainerFrame.h"
//
// NS_NewToolbarFrame
//
// Creates a new Toolbar frame and returns it in |aNewFrame|
//
nsresult
NS_NewGrippyFrame ( nsIFrame** aNewFrame )
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsGrippyFrame* it = new nsGrippyFrame;
if (nsnull == it)
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = it;
return NS_OK;
} // NS_NewGrippyFrame
nsGrippyFrame::nsGrippyFrame():mCollapsed(PR_FALSE)
{
}
void
nsGrippyFrame::MouseClicked(nsIPresContext& aPresContext)
{
nsIFrame* splitter;
nsScrollbarButtonFrame::GetParentWithTag(nsXULAtoms::splitter, this, splitter);
if (splitter == nsnull)
return;
// get the splitters content node
nsCOMPtr<nsIContent> content;
splitter->GetContent(getter_AddRefs(content));
nsString a = "collapsed";
nsString value;
if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttribute(kNameSpaceID_None, nsXULAtoms::state, value))
{
if (value=="collapsed")
a = "open";
}
content->SetAttribute(kNameSpaceID_None, nsXULAtoms::state, a, PR_TRUE);
}
/*
void
nsGrippyFrame::MouseClicked(nsIPresContext& aPresContext)
{
nsString style;
if (mCollapsed) {
style = mCollapsedChildStyle;
} else {
// when clicked see if we are in a splitter.
nsIFrame* splitter;
nsScrollbarButtonFrame::GetParentWithTag(nsXULAtoms::splitter, this, splitter);
if (splitter == nsnull)
return;
// get the splitters content node
nsCOMPtr<nsIContent> content;
splitter->GetContent(getter_AddRefs(content));
// get the collapse attribute. If the attribute is not set collapse
// the child before otherwise collapse the child after
PRBool before = PR_TRUE;
nsString value;
if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttribute(kNameSpaceID_None, nsXULAtoms::collapse, value))
{
if (value=="after")
before = PR_FALSE;
}
// find the child just in the box just before the splitter. If we are not currently collapsed then
// then get the childs style attribute and store it. Then set the child style attribute to be display none.
// if we are already collapsed then set the child's style back to our stored value.
nsIFrame* child = GetChildBeforeAfter(splitter,before);
if (child == nsnull)
return;
child->GetContent(getter_AddRefs(mCollapsedChild));
style = "visibility: collapse";
mCollapsedChildStyle = "";
mCollapsedChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::style, mCollapsedChildStyle);
}
mCollapsedChild->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::style, style, PR_TRUE);
mCollapsed = !mCollapsed;
}
*/
nsIFrame*
nsGrippyFrame::GetChildBeforeAfter(nsIFrame* start, PRBool before)
{
nsIFrame* parent = nsnull;
start->GetParent(&parent);
PRInt32 index = IndexOf(parent,start);
PRInt32 count = CountFrames(parent);
if (index == -1)
return nsnull;
if (before) {
if (index == 0) {
return nsnull;
}
return GetChildAt(parent, index-1);
}
if (index == count-1)
return nsnull;
return GetChildAt(parent, index+1);
}
PRInt32
nsGrippyFrame::IndexOf(nsIFrame* parent, nsIFrame* child)
{
PRInt32 count = 0;
nsIFrame* childFrame;
parent->FirstChild(nsnull, &childFrame);
while (nsnull != childFrame)
{
if (childFrame == child)
return count;
nsresult rv = childFrame->GetNextSibling(&childFrame);
NS_ASSERTION(rv == NS_OK,"failed to get next child");
count++;
}
return -1;
}
PRInt32
nsGrippyFrame::CountFrames(nsIFrame* aFrame)
{
PRInt32 count = 0;
nsIFrame* childFrame;
aFrame->FirstChild(nsnull, &childFrame);
while (nsnull != childFrame)
{
nsresult rv = childFrame->GetNextSibling(&childFrame);
NS_ASSERTION(rv == NS_OK,"failed to get next child");
count++;
}
return count;
}
nsIFrame*
nsGrippyFrame::GetChildAt(nsIFrame* parent, PRInt32 index)
{
PRInt32 count = 0;
nsIFrame* childFrame;
parent->FirstChild(nsnull, &childFrame);
while (nsnull != childFrame)
{
if (count == index)
return childFrame;
nsresult rv = childFrame->GetNextSibling(&childFrame);
NS_ASSERTION(rv == NS_OK,"failed to get next child");
count++;
}
return nsnull;
}
NS_IMETHODIMP
nsGrippyFrame::GetFrameName(nsString& aResult) const
{
aResult = "Grippy";
return NS_OK;
}

View File

@@ -1,63 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
/**
Eric D Vaughan
This class lays out its children either vertically or horizontally
**/
#ifndef nsGrippyFrame_h___
#define nsGrippyFrame_h___
#include "nsTitledButtonFrame.h"
#include "nsCOMPtr.h"
#include "nsIContent.h"
class nsGrippyFrame : public nsTitledButtonFrame
{
public:
friend nsresult NS_NewGrippyFrame(nsIFrame** aNewFrame);
NS_IMETHOD GetFrameName(nsString& aResult) const;
static nsIFrame* GetChildBeforeAfter(nsIFrame* start, PRBool before);
static nsIFrame* GetChildAt(nsIFrame* parent, PRInt32 index);
static PRInt32 IndexOf(nsIFrame* parent, nsIFrame* child);
static PRInt32 CountFrames(nsIFrame* aFrame);
nsGrippyFrame();
protected:
virtual void MouseClicked(nsIPresContext& aPresContext);
private:
PRBool mCollapsed;
nsString mCollapsedChildStyle;
nsCOMPtr<nsIContent> mCollapsedChild;
PRBool mDidDrag;
}; // class nsTabFrame
#endif

View File

@@ -1,77 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
/**
Eric D Vaughan
nsBoxFrame is a frame that can lay its children out either vertically or horizontally.
It lays them out according to a min max or preferred size.
**/
#ifndef nsIBox_h___
#define nsIBox_h___
class nsIPresContext;
class nsIFrame;
struct nsHTMLReflowState;
class nsBoxInfo;
// {02A560C0-01BF-11d3-B35C-00A0CC3C1CDE}
#define NS_IBOX_IID { 0x2a560c0, 0x1bf, 0x11d3, { 0xb3, 0x5c, 0x0, 0xa0, 0xcc, 0x3c, 0x1c, 0xde } }
static NS_DEFINE_IID(kIBoxIID, NS_IBOX_IID);
class nsBoxInfo {
public:
nsSize prefSize;
nsSize minSize;
nsSize maxSize;
float flex;
nsBoxInfo() { clear(); }
virtual void clear()
{
prefSize.width = 0;
prefSize.height = 0;
minSize.width = 0;
minSize.height = 0;
flex = 0.0;
maxSize.width = NS_INTRINSICSIZE;
maxSize.height = NS_INTRINSICSIZE;
}
};
class nsIBox : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IBOX_IID; return iid; }
NS_IMETHOD GetBoxInfo(nsIPresContext& aPresContext, const nsHTMLReflowState& aReflowState, nsBoxInfo& aSize)=0;
NS_IMETHOD Dirty(nsIPresContext& aPresContext, const nsHTMLReflowState& aReflowState, nsIFrame*& incrementalChild)=0;
};
#endif

View File

@@ -1,77 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#ifndef __nsIColorPicker_h__
#define __nsIColorPicker_h__
#include "nsISupports.h"
#include "nsrootidl.h"
#include "nsIPresContext.h"
#include "nsIRenderingContext.h"
/* starting interface: nsIColorPicker */
#define NS_ICOLORPICKER_IID_STR "ed133d04-1dd1-11b2-957f-a04e70608d6e"
#define NS_ICOLORPICKER_IID \
{0xed133d04, 0x1dd1, 0x11b2, \
{ 0x95, 0x7f, 0xa0, 0x4e, 0x70, 0x60, 0x8d, 0x6e }}
class nsIColorPicker : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICOLORPICKER_IID)
/* void Init (in nsIContent aContent); */
NS_IMETHOD Init(nsIContent * aContent) = 0;
/* void Paint (in nsIPresContext aPresContext, in nsIRenderingContext aRenderingContext); */
NS_IMETHOD Paint(nsIPresContext * aPresContext, nsIRenderingContext * aRenderingContext) = 0;
/* void GetColor (in PRInt32 aX, in PRInt32 aY, out string aColor); */
NS_IMETHOD GetColor(PRInt32 aX, PRInt32 aY, char **aColor) = 0;
/* void SetColor (in PRInt32 aWidth, in PRInt32 aHeight); */
NS_IMETHOD SetSize(PRInt32 aWidth, PRInt32 aHeight) = 0;
/* void GetSize (out PRInt32 aWidth, out PRInt32 aHeight); */
NS_IMETHOD GetSize(PRInt32 *aWidth, PRInt32 *aHeight) = 0;
};
/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_NSICOLORPICKER \
NS_IMETHOD Init(nsIContent * aContent); \
NS_IMETHOD Paint(nsIPresContext * aPresContext, nsIRenderingContext * aRenderingContext); \
NS_IMETHOD GetColor(PRInt32 aX, PRInt32 aY, char **aColor); \
NS_IMETHOD SetSize(PRInt32 aWidth, PRInt32 aHeight); \
NS_IMETHOD GetSize(PRInt32 *aWidth, PRInt32 *aHeight);
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
#define NS_FORWARD_NSICOLORPICKER(_to) \
NS_IMETHOD Init(nsIContent * aContent) { return _to ## Init(aContent); } \
NS_IMETHOD Paint(nsIPresContext * aPresContext, nsIRenderingContext * aRenderingContext) { return _to ## Paint(aPresContext, aRenderingContext); } \
NS_IMETHOD GetColor(PRInt32 aX, PRInt32 aY, char **aColor) { return _to ## GetColor(aX, aY, aColor); } \
NS_IMETHOD SetSize(PRInt32 aWidth, PRInt32 aHeight) { return _to ## SetSize(aWidth, aHeight); } \
NS_IMETHOD GetSize(PRInt32 *aWidth, PRInt32 *aHeight) { return _to ## GetSize(aWidth, aHeight); }
#endif /* __nsIColorPicker_h__ */

View File

@@ -1,63 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsIMenuFrame_h___
#define nsIMenuFrame_h___
// {6A4CDE51-6C05-11d3-BB50-00104B7B7DEB}
#define NS_IMENUFRAME_IID \
{ 0x6a4cde51, 0x6c05, 0x11d3, { 0xbb, 0x50, 0x0, 0x10, 0x4b, 0x7b, 0x7d, 0xeb } }
class nsIMenuParent;
enum nsMenuType {
eMenuType_Normal = 0,
eMenuType_Checkbox = 1,
eMenuType_Radio = 2
};
class nsIMenuFrame : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IMENUFRAME_IID; return iid; }
NS_IMETHOD ActivateMenu(PRBool aFlag) = 0;
NS_IMETHOD SelectMenu(PRBool aFlag) = 0;
NS_IMETHOD OpenMenu(PRBool aFlag) = 0;
NS_IMETHOD MenuIsOpen(PRBool& aResult) = 0;
NS_IMETHOD MenuIsContainer(PRBool& aResult) = 0;
NS_IMETHOD MenuIsChecked(PRBool& aResult) = 0;
NS_IMETHOD SelectFirstItem() = 0;
NS_IMETHOD Escape(PRBool& aHandledFlag) = 0;
NS_IMETHOD Enter() = 0;
NS_IMETHOD ShortcutNavigation(PRUint32 aLetter, PRBool& aHandledFlag) = 0;
NS_IMETHOD KeyboardNavigation(PRUint32 aDirection, PRBool& aHandledFlag) = 0;
NS_IMETHOD GetMenuParent(nsIMenuParent** aMenuParent) = 0;
NS_IMETHOD GetRadioGroupName(nsString &aName) = 0;
NS_IMETHOD GetMenuType(nsMenuType &aType) = 0;
NS_IMETHOD MarkAsGenerated() = 0;
};
#endif

View File

@@ -1,52 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsIMenuParent_h___
#define nsIMenuParent_h___
// {D407BF61-3EFA-11d3-97FA-00400553EEF0}
#define NS_IMENUPARENT_IID \
{ 0xd407bf61, 0x3efa, 0x11d3, { 0x97, 0xfa, 0x0, 0x40, 0x5, 0x53, 0xee, 0xf0 } }
class nsIMenuFrame;
class nsIMenuParent : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IMENUPARENT_IID; return iid; }
NS_IMETHOD SetCurrentMenuItem(nsIMenuFrame* aMenuItem) = 0;
NS_IMETHOD GetNextMenuItem(nsIMenuFrame* aStart, nsIMenuFrame** aResult) = 0;
NS_IMETHOD GetPreviousMenuItem(nsIMenuFrame* aStart, nsIMenuFrame** aResult) = 0;
NS_IMETHOD SetActive(PRBool aActiveFlag) = 0;
NS_IMETHOD GetIsActive(PRBool& isActive) = 0;
NS_IMETHOD GetWidget(nsIWidget **aWidget) = 0;
NS_IMETHOD IsMenuBar(PRBool& isMenuBar) = 0;
NS_IMETHOD DismissChain() = 0;
NS_IMETHOD HideChain() = 0;
NS_IMETHOD CreateDismissalListener() = 0;
};
#endif

View File

@@ -1,44 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsIScrollbarListener_h___
#define nsIScrollbarListener_h___
// {A0ADBD81-2911-11d3-97FA-00400553EEF0}
#define NS_ISCROLLBARLISTENER_IID \
{ 0xa0adbd81, 0x2911, 0x11d3, { 0x97, 0xfa, 0x0, 0x40, 0x5, 0x53, 0xee, 0xf0 } }
static NS_DEFINE_IID(kIScrollbarListenerIID, NS_ISCROLLBARLISTENER_IID);
class nsIPresContext;
class nsIScrollbarListener : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_ISCROLLBARLISTENER_IID; return iid; }
NS_IMETHOD PositionChanged(nsIPresContext& aPresContext, PRInt32 aOldIndex, PRInt32 aNewIndex) = 0;
NS_IMETHOD PagedUpDown() = 0;
// NS_IMETHOD GoingAway() = 0;
};
#endif

View File

@@ -1,537 +0,0 @@
/* -*- 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 "nsMenuBarFrame.h"
#include "nsIContent.h"
#include "prtypes.h"
#include "nsIAtom.h"
#include "nsIPresContext.h"
#include "nsIStyleContext.h"
#include "nsCSSRendering.h"
#include "nsINameSpaceManager.h"
#include "nsIDocument.h"
#include "nsIDOMEventReceiver.h"
#include "nsXULAtoms.h"
#include "nsHTMLAtoms.h"
#include "nsMenuFrame.h"
#include "nsIView.h"
#include "nsIViewManager.h"
#include "nsMenuPopupFrame.h"
static NS_DEFINE_IID(kIFrameIID, NS_IFRAME_IID);
//
// NS_NewMenuBarFrame
//
// Wrapper for creating a new menu Bar container
//
nsresult
NS_NewMenuBarFrame(nsIFrame** aNewFrame)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsMenuBarFrame* it = new nsMenuBarFrame;
if ( !it )
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = it;
return NS_OK;
}
NS_IMETHODIMP_(nsrefcnt)
nsMenuBarFrame::AddRef(void)
{
return NS_OK;
}
NS_IMETHODIMP_(nsrefcnt)
nsMenuBarFrame::Release(void)
{
return NS_OK;
}
NS_IMETHODIMP nsMenuBarFrame::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
*aInstancePtr = NULL;
if (aIID.Equals(nsIMenuParent::GetIID())) {
*aInstancePtr = (void*)(nsIMenuParent*) this;
NS_ADDREF_THIS();
return NS_OK;
}
return nsToolbarFrame::QueryInterface(aIID, aInstancePtr);
}
//
// nsMenuBarFrame cntr
//
nsMenuBarFrame::nsMenuBarFrame()
:mIsActive(PR_FALSE), mTarget(nsnull)
{
} // cntr
nsMenuBarFrame::~nsMenuBarFrame()
{
}
NS_IMETHODIMP
nsMenuBarFrame::Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsToolbarFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
// XXX hack
mPresContext = &aPresContext;
// Create the menu bar listener.
mMenuBarListener = new nsMenuBarListener(this);
// Hook up the menu bar as a key listener (capturer) on the whole document. It will see every
// key press that occurs before anyone else does and will know when to take control.
nsCOMPtr<nsIDocument> doc;
aContent->GetDocument(*getter_AddRefs(doc));
nsCOMPtr<nsIDOMEventReceiver> target = do_QueryInterface(doc);
nsIDOMEventListener* domEventListener = (nsIDOMKeyListener*)mMenuBarListener;
mTarget = target;
target->AddEventListener("keypress", domEventListener, PR_TRUE);
target->AddEventListener("keydown", domEventListener, PR_TRUE);
target->AddEventListener("keyup", domEventListener, PR_TRUE);
return rv;
}
NS_IMETHODIMP
nsMenuBarFrame::SetActive(PRBool aActiveFlag)
{
mIsActive = aActiveFlag;
return NS_OK;
}
void
nsMenuBarFrame::ToggleMenuActiveState()
{
if (mIsActive) {
// Deactivate the menu bar
mIsActive = PR_FALSE;
if (mCurrentMenu) {
// Deactivate the menu.
mCurrentMenu->OpenMenu(PR_FALSE);
mCurrentMenu->SelectMenu(PR_FALSE);
mCurrentMenu = nsnull;
}
}
else {
// Activate the menu bar
SetActive(PR_TRUE);
// Set the active menu to be the top left item (e.g., the File menu).
// We use an attribute called "active" to track the current active menu.
nsCOMPtr<nsIContent> firstMenuItem;
nsIMenuFrame* firstFrame;
GetNextMenuItem(nsnull, &firstFrame);
if (firstFrame) {
firstFrame->SelectMenu(PR_TRUE);
// Track this item for keyboard navigation.
mCurrentMenu = firstFrame;
}
}
}
nsIMenuFrame*
nsMenuBarFrame::FindMenuWithShortcut(PRUint32 aLetter)
{
// Enumerate over our list of frames.
nsIFrame* currFrame = mFrames.FirstChild();
while (currFrame) {
nsCOMPtr<nsIContent> current;
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
if (IsValidItem(current)) {
// Get the shortcut attribute.
nsString shortcutKey = "";
current->GetAttribute(kNameSpaceID_None, nsXULAtoms::accesskey, shortcutKey);
shortcutKey.ToUpperCase();
if (shortcutKey.Length() > 0) {
// We've got something.
PRUnichar shortcutChar = shortcutKey.CharAt(0);
if (shortcutChar == aLetter) {
// We match!
nsCOMPtr<nsIMenuFrame> menuFrame = do_QueryInterface(currFrame);
if (menuFrame)
return menuFrame.get();
return nsnull;
}
}
}
currFrame->GetNextSibling(&currFrame);
}
return nsnull;
}
void
nsMenuBarFrame::ShortcutNavigation(PRUint32 aLetter, PRBool& aHandledFlag)
{
if (mCurrentMenu) {
PRBool isOpen = PR_FALSE;
mCurrentMenu->MenuIsOpen(isOpen);
if (isOpen) {
// No way this applies to us. Give it to our child.
mCurrentMenu->ShortcutNavigation(aLetter, aHandledFlag);
return;
}
}
// This applies to us. Let's see if one of the shortcuts applies
nsIMenuFrame* result = FindMenuWithShortcut(aLetter);
if (result) {
// We got one!
aHandledFlag = PR_TRUE;
mIsActive = PR_TRUE;
SetCurrentMenuItem(result);
result->OpenMenu(PR_TRUE);
result->SelectFirstItem();
}
}
void
nsMenuBarFrame::KeyboardNavigation(PRUint32 aDirection)
{
if (!mCurrentMenu)
return;
PRBool isContainer = PR_FALSE;
PRBool isOpen = PR_FALSE;
mCurrentMenu->MenuIsContainer(isContainer);
mCurrentMenu->MenuIsOpen(isOpen);
PRBool handled = PR_FALSE;
if (isOpen) {
// Let the child menu try to handle it.
mCurrentMenu->KeyboardNavigation(aDirection, handled);
}
if (handled)
return;
if (aDirection == NS_VK_RIGHT || aDirection == NS_VK_LEFT) {
nsIMenuFrame* nextItem;
if (aDirection == NS_VK_RIGHT)
GetNextMenuItem(mCurrentMenu, &nextItem);
else GetPreviousMenuItem(mCurrentMenu, &nextItem);
SetCurrentMenuItem(nextItem);
if (nextItem) {
PRBool nextIsOpen;
nextItem->MenuIsOpen(nextIsOpen);
if (nextIsOpen) {
// Select the first item.
nextItem->SelectFirstItem();
}
}
}
else if (aDirection == NS_VK_UP || aDirection == NS_VK_DOWN) {
// Open the menu and select its first item.
mCurrentMenu->OpenMenu(PR_TRUE);
mCurrentMenu->SelectFirstItem();
}
}
NS_IMETHODIMP
nsMenuBarFrame::GetNextMenuItem(nsIMenuFrame* aStart, nsIMenuFrame** aResult)
{
nsIFrame* currFrame = nsnull;
nsIFrame* startFrame = nsnull;
if (aStart) {
aStart->QueryInterface(kIFrameIID, (void**)&currFrame);
if (currFrame) {
startFrame = currFrame;
currFrame->GetNextSibling(&currFrame);
}
}
else currFrame = mFrames.FirstChild();
while (currFrame) {
nsCOMPtr<nsIContent> current;
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
if (IsValidItem(current)) {
nsCOMPtr<nsIMenuFrame> menuFrame = do_QueryInterface(currFrame);
*aResult = menuFrame.get();
NS_IF_ADDREF(*aResult);
return NS_OK;
}
currFrame->GetNextSibling(&currFrame);
}
currFrame = mFrames.FirstChild();
// Still don't have anything. Try cycling from the beginning.
while (currFrame && currFrame != startFrame) {
nsCOMPtr<nsIContent> current;
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
if (IsValidItem(current)) {
nsCOMPtr<nsIMenuFrame> menuFrame = do_QueryInterface(currFrame);
*aResult = menuFrame.get();
NS_IF_ADDREF(*aResult);
return NS_OK;
}
currFrame->GetNextSibling(&currFrame);
}
// No luck. Just return our start value.
*aResult = aStart;
return NS_OK;
}
NS_IMETHODIMP
nsMenuBarFrame::GetPreviousMenuItem(nsIMenuFrame* aStart, nsIMenuFrame** aResult)
{
nsIFrame* currFrame = nsnull;
nsIFrame* startFrame = nsnull;
if (aStart) {
aStart->QueryInterface(kIFrameIID, (void**)&currFrame);
if (currFrame) {
startFrame = currFrame;
currFrame = mFrames.GetPrevSiblingFor(currFrame);
}
}
else currFrame = mFrames.LastChild();
while (currFrame) {
nsCOMPtr<nsIContent> current;
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
if (IsValidItem(current)) {
nsCOMPtr<nsIMenuFrame> menuFrame = do_QueryInterface(currFrame);
*aResult = menuFrame.get();
NS_IF_ADDREF(*aResult);
return NS_OK;
}
currFrame = mFrames.GetPrevSiblingFor(currFrame);
}
currFrame = mFrames.LastChild();
// Still don't have anything. Try cycling from the end.
while (currFrame && currFrame != startFrame) {
nsCOMPtr<nsIContent> current;
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
if (IsValidItem(current)) {
nsCOMPtr<nsIMenuFrame> menuFrame = do_QueryInterface(currFrame);
*aResult = menuFrame.get();
NS_IF_ADDREF(*aResult);
return NS_OK;
}
currFrame = mFrames.GetPrevSiblingFor(currFrame);
}
// No luck. Just return our start value.
*aResult = aStart;
return NS_OK;
}
NS_IMETHODIMP nsMenuBarFrame::SetCurrentMenuItem(nsIMenuFrame* aMenuItem)
{
if (mCurrentMenu == aMenuItem)
return NS_OK;
PRBool wasOpen = PR_FALSE;
// Unset the current child.
if (mCurrentMenu) {
mCurrentMenu->MenuIsOpen(wasOpen);
mCurrentMenu->SelectMenu(PR_FALSE);
if (wasOpen)
mCurrentMenu->OpenMenu(PR_FALSE);
}
// Set the new child.
if (aMenuItem) {
aMenuItem->SelectMenu(PR_TRUE);
aMenuItem->MarkAsGenerated(); // Have the menu building. Get it ready to be shown.
if (wasOpen)
aMenuItem->OpenMenu(PR_TRUE);
}
mCurrentMenu = aMenuItem;
return NS_OK;
}
void
nsMenuBarFrame::Escape()
{
if (!mCurrentMenu)
return;
// See if our menu is open.
PRBool isOpen = PR_FALSE;
mCurrentMenu->MenuIsOpen(isOpen);
if (isOpen) {
// Let the child menu handle this.
PRBool handled = PR_FALSE;
mCurrentMenu->Escape(handled);
if (!handled) {
// Close up this menu but keep our current menu item
// designation.
mCurrentMenu->OpenMenu(PR_FALSE);
}
return;
}
// It's us. Just set our active flag to false.
mIsActive = PR_FALSE;
// Clear our current menu item if we've got one.
SetCurrentMenuItem(nsnull);
// Clear out our dismissal listener
if (nsMenuFrame::mDismissalListener)
nsMenuFrame::mDismissalListener->Unregister();
}
void
nsMenuBarFrame::Enter()
{
if (!mCurrentMenu)
return;
// See if our menu is open.
PRBool isOpen = PR_FALSE;
mCurrentMenu->MenuIsOpen(isOpen);
if (isOpen) {
// Let the child menu handle this.
mCurrentMenu->Enter();
return;
}
// It's us. Open the current menu.
mCurrentMenu->OpenMenu(PR_TRUE);
mCurrentMenu->SelectFirstItem();
}
NS_IMETHODIMP
nsMenuBarFrame::HideChain()
{
// Stop capturing rollups
// (must do this during Hide, which happens before the menu item is executed,
// since this reinstates normal event handling.)
if (nsMenuFrame::mDismissalListener)
nsMenuFrame::mDismissalListener->Unregister();
if (mCurrentMenu) {
mCurrentMenu->ActivateMenu(PR_FALSE);
mCurrentMenu->SelectMenu(PR_FALSE);
}
return NS_OK;
}
NS_IMETHODIMP
nsMenuBarFrame::DismissChain()
{
// Stop capturing rollups
if (nsMenuFrame::mDismissalListener)
nsMenuFrame::mDismissalListener->Unregister();
SetCurrentMenuItem(nsnull);
SetActive(PR_FALSE);
return NS_OK;
}
NS_IMETHODIMP
nsMenuBarFrame::GetWidget(nsIWidget **aWidget)
{
// Get parent view
nsIView * view = nsnull;
nsMenuPopupFrame::GetNearestEnclosingView(mPresContext, this, &view);
if (!view)
return NS_OK;
view->GetWidget(*aWidget);
return NS_OK;
}
NS_IMETHODIMP
nsMenuBarFrame::CreateDismissalListener()
{
NS_ADDREF(nsMenuFrame::mDismissalListener = new nsMenuDismissalListener());
return NS_OK;
}
PRBool
nsMenuBarFrame::IsValidItem(nsIContent* aContent)
{
nsCOMPtr<nsIAtom> tag;
aContent->GetTag(*getter_AddRefs(tag));
if (tag && (tag.get() == nsXULAtoms::menu ||
tag.get() == nsXULAtoms::menuitem) &&
!IsDisabled(aContent))
return PR_TRUE;
return PR_FALSE;
}
PRBool
nsMenuBarFrame::IsDisabled(nsIContent* aContent)
{
nsString disabled = "";
aContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, disabled);
if (disabled == "true")
return PR_TRUE;
return PR_FALSE;
}
NS_IMETHODIMP
nsMenuBarFrame::Destroy(nsIPresContext& aPresContext)
{
mTarget->RemoveEventListener("keypress", mMenuBarListener, PR_TRUE);
mTarget->RemoveEventListener("keydown", mMenuBarListener, PR_TRUE);
mTarget->RemoveEventListener("keyup", mMenuBarListener, PR_TRUE);
delete mMenuBarListener;
mMenuBarListener = nsnull;
return nsToolbarFrame::Destroy(aPresContext);
}

View File

@@ -1,108 +0,0 @@
/* -*- 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.
*/
//
// nsMenuBarFrame
//
#ifndef nsMenuBarFrame_h__
#define nsMenuBarFrame_h__
#include "prtypes.h"
#include "nsIAtom.h"
#include "nsCOMPtr.h"
#include "nsToolbarFrame.h"
#include "nsMenuBarListener.h"
#include "nsIMenuParent.h"
#include "nsIWidget.h"
class nsIContent;
class nsIMenuFrame;
nsresult NS_NewMenuBarFrame(nsIFrame** aResult) ;
class nsMenuBarFrame : public nsToolbarFrame, public nsIMenuParent
{
public:
nsMenuBarFrame();
~nsMenuBarFrame();
NS_DECL_ISUPPORTS
// nsIMenuParentInterface
NS_IMETHOD SetCurrentMenuItem(nsIMenuFrame* aMenuItem);
NS_IMETHOD GetNextMenuItem(nsIMenuFrame* aStart, nsIMenuFrame** aResult);
NS_IMETHOD GetPreviousMenuItem(nsIMenuFrame* aStart, nsIMenuFrame** aResult);
NS_IMETHOD SetActive(PRBool aActiveFlag);
NS_IMETHOD GetIsActive(PRBool& isActive) { isActive = IsActive(); return NS_OK; };
NS_IMETHOD IsMenuBar(PRBool& isMenuBar) { isMenuBar = PR_TRUE; return NS_OK; };
NS_IMETHOD IsActive() { return mIsActive; };
// Closes up the chain of open cascaded menus.
NS_IMETHOD DismissChain();
// Hides the chain of cascaded menus without closing them up.
NS_IMETHOD HideChain();
NS_IMETHOD GetWidget(nsIWidget **aWidget);
// The dismissal listener gets created and attached to the window.
NS_IMETHOD CreateDismissalListener();
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow);
NS_IMETHOD Destroy(nsIPresContext& aPresContext);
// Non-interface helpers
// Called when a menu on the menu bar is clicked on.
void ToggleMenuActiveState();
// Used to move up, down, left, and right in menus.
void KeyboardNavigation(PRUint32 aDirection);
// Used to handle ALT+key combos
void ShortcutNavigation(PRUint32 aLetter, PRBool& aHandledFlag);
nsIMenuFrame* FindMenuWithShortcut(PRUint32 aLetter);
// Called when the ESC key is held down to close levels of menus.
void Escape();
// Called to execute a menu item.
void Enter();
PRBool IsValidItem(nsIContent* aContent);
PRBool IsDisabled(nsIContent* aContent);
protected:
nsMenuBarListener* mMenuBarListener; // The listener that tells us about key and mouse events.
PRBool mIsActive; // Whether or not the menu bar is active (a menu item is highlighted or shown).
nsIMenuFrame* mCurrentMenu; // The current menu that is active.
nsIDOMEventReceiver* mTarget;
// XXX Hack
nsIPresContext* mPresContext; // weak reference
}; // class nsMenuBarFrame
#endif

View File

@@ -1,190 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsMenuBarListener.h"
#include "nsMenuBarFrame.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMEventListener.h"
// Drag & Drop, Clipboard
#include "nsIServiceManager.h"
#include "nsWidgetsCID.h"
#include "nsCOMPtr.h"
#include "nsIDOMKeyEvent.h"
#include "nsIPresContext.h"
#include "nsIContent.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsXULAtoms.h"
#include "nsIEventStateManager.h"
#include "nsIViewManager.h"
#include "nsIView.h"
#include "nsISupportsArray.h"
/*
* nsMenuBarListener implementation
*/
NS_IMPL_ADDREF(nsMenuBarListener)
NS_IMPL_RELEASE(nsMenuBarListener)
////////////////////////////////////////////////////////////////////////
nsMenuBarListener::nsMenuBarListener(nsMenuBarFrame* aMenuBar)
:mAltKeyDown(PR_FALSE)
{
NS_INIT_REFCNT();
mMenuBarFrame = aMenuBar;
}
////////////////////////////////////////////////////////////////////////
nsMenuBarListener::~nsMenuBarListener()
{
}
////////////////////////////////////////////////////////////////////////
nsresult
nsMenuBarListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(nsCOMTypeInfo<nsIDOMEventReceiver>::GetIID())) {
*aInstancePtr = (void*)(nsIDOMEventListener*)(nsIDOMKeyListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsCOMTypeInfo<nsIDOMKeyListener>::GetIID())) {
*aInstancePtr = (void*)(nsIDOMKeyListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
*aInstancePtr = (void*)(nsISupports*)(nsIDOMKeyListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////
nsresult
nsMenuBarListener::KeyUp(nsIDOMEvent* aKeyEvent)
{
// On a press of the ALT key by itself, we toggle the menu's
// active/inactive state.
// Get the ascii key code.
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
PRUint32 theChar;
keyEvent->GetKeyCode(&theChar);
if (theChar == NS_VK_ALT && mAltKeyDown) {
// The ALT key was down and is now up.
mAltKeyDown = PR_FALSE;
mMenuBarFrame->ToggleMenuActiveState();
}
PRBool active = mMenuBarFrame->IsActive();
if (active)
return NS_ERROR_BASE; // I am consuming event
return NS_OK; // means I am NOT consuming event
}
////////////////////////////////////////////////////////////////////////
nsresult
nsMenuBarListener::KeyDown(nsIDOMEvent* aKeyEvent)
{
PRBool active = mMenuBarFrame->IsActive();
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
PRUint32 theChar;
keyEvent->GetKeyCode(&theChar);
if (theChar == NS_VK_ALT) {
// The ALT key just went down. Track this.
mAltKeyDown = PR_TRUE;
return NS_OK;
}
PRBool altKeyWasDown = mAltKeyDown;
mAltKeyDown = PR_FALSE;
if (theChar == NS_VK_LEFT ||
theChar == NS_VK_RIGHT ||
theChar == NS_VK_UP ||
theChar == NS_VK_DOWN) {
// The arrow keys were pressed. User is moving around within
// the menus.
if (active)
mMenuBarFrame->KeyboardNavigation(theChar);
}
else if (theChar == NS_VK_ESCAPE) {
// Close one level.
if (active)
mMenuBarFrame->Escape();
}
else if (theChar == NS_VK_ENTER ||
theChar == NS_VK_RETURN) {
// Open one level.
if (active)
mMenuBarFrame->Enter();
}
else if (active || altKeyWasDown) {
// Get the character code.
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
if (keyEvent) {
// See if a letter was pressed.
PRUint32 charCode;
keyEvent->GetKeyCode(&charCode);
// Do shortcut navigation.
// A letter was pressed. We want to see if a shortcut gets matched. If
// so, we'll know the menu got activated.
mMenuBarFrame->ShortcutNavigation(charCode, active);
}
}
if (active)
return NS_ERROR_BASE; // I am consuming event
return NS_OK; // means I am NOT consuming event
}
////////////////////////////////////////////////////////////////////////
nsresult
nsMenuBarListener::KeyPress(nsIDOMEvent* aKeyEvent)
{
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
PRBool active = mMenuBarFrame->IsActive();
if (active)
return NS_ERROR_BASE; // I am consuming event
return NS_OK; // means I am NOT consuming event
}
////////////////////////////////////////////////////////////////////////
nsresult
nsMenuBarListener::HandleEvent(nsIDOMEvent* aEvent)
{
return NS_OK;
}

View File

@@ -1,56 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsMenuBarListener_h__
#define nsMenuBarListener_h__
#include "nsIDOMMouseMotionListener.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMEventReceiver.h"
class nsMenuBarFrame;
class nsIPresContext;
/** editor Implementation of the DragListener interface
*/
class nsMenuBarListener : public nsIDOMKeyListener
{
public:
/** default constructor
*/
nsMenuBarListener(nsMenuBarFrame* aMenuBar);
/** default destructor
*/
virtual ~nsMenuBarListener();
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
virtual nsresult KeyUp(nsIDOMEvent* aMouseEvent);
virtual nsresult KeyDown(nsIDOMEvent* aMouseEvent);
virtual nsresult KeyPress(nsIDOMEvent* aMouseEvent);
NS_DECL_ISUPPORTS
protected:
nsMenuBarFrame* mMenuBarFrame; // The menu bar object.
PRBool mAltKeyDown; // Whether or not the ALT key is currently down.
};
#endif

View File

@@ -1,140 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsMenuDismissalListener.h"
#include "nsIMenuParent.h"
#include "nsMenuFrame.h"
/*
* nsMenuDismissalListener implementation
*/
NS_IMPL_ADDREF(nsMenuDismissalListener)
NS_IMPL_RELEASE(nsMenuDismissalListener)
////////////////////////////////////////////////////////////////////////
nsMenuDismissalListener::nsMenuDismissalListener() :
mWidget(0), mEnabled(PR_TRUE)
{
NS_INIT_REFCNT();
mMenuParent = nsnull;
}
////////////////////////////////////////////////////////////////////////
nsMenuDismissalListener::~nsMenuDismissalListener()
{
}
////////////////////////////////////////////////////////////////////////
nsresult
nsMenuDismissalListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(nsCOMTypeInfo<nsIDOMEventReceiver>::GetIID())) {
*aInstancePtr = (void*)(nsIDOMEventListener*)(nsIDOMKeyListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsCOMTypeInfo<nsIDOMMouseListener>::GetIID())) {
*aInstancePtr = (void*)(nsIDOMMouseListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsCOMTypeInfo<nsIRollupListener>::GetIID())) {
*aInstancePtr = (void*)(nsIRollupListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
*aInstancePtr = (void*)(nsISupports*)(nsIDOMMouseListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////
nsresult
nsMenuDismissalListener::MouseDown(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
void
nsMenuDismissalListener::SetCurrentMenuParent(nsIMenuParent* aMenuParent)
{
if (aMenuParent == mMenuParent)
return;
nsCOMPtr<nsIRollupListener> kungFuDeathGrip = this;
Unregister();
mMenuParent = aMenuParent;
if (!aMenuParent)
return;
nsCOMPtr<nsIWidget> widget;
aMenuParent->GetWidget(getter_AddRefs(widget));
if (!widget)
return;
widget->CaptureRollupEvents(this, PR_TRUE, PR_FALSE);
mWidget = widget;
NS_ADDREF(nsMenuFrame::mDismissalListener = this);
}
NS_IMETHODIMP
nsMenuDismissalListener::Rollup()
{
if (mEnabled) {
if (mMenuParent) {
AddRef();
mMenuParent->HideChain();
mMenuParent->DismissChain();
Release();
}
else
Unregister();
}
return NS_OK;
}
NS_IMETHODIMP
nsMenuDismissalListener::Unregister()
{
if (mWidget)
mWidget->CaptureRollupEvents(this, PR_FALSE, PR_FALSE);
NS_RELEASE(nsMenuFrame::mDismissalListener);
return NS_OK;
}
NS_IMETHODIMP
nsMenuDismissalListener::EnableListener(PRBool aEnabled)
{
mEnabled = aEnabled;
return NS_OK;
}

View File

@@ -1,67 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsMenuDismissalListener_h__
#define nsMenuDismissalListener_h__
#include "nsIWidget.h"
#include "nsIDOMMouseListener.h"
#include "nsIRollupListener.h"
#include "nsIDOMEventReceiver.h"
class nsMenuPopupFrame;
class nsIPresContext;
class nsIMenuParent;
/** editor Implementation of the DragListener interface
*/
class nsMenuDismissalListener : public nsIDOMMouseListener, public nsIRollupListener
{
public:
/** default constructor
*/
nsMenuDismissalListener();
/** default destructor
*/
virtual ~nsMenuDismissalListener();
virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; };
virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent) { return NS_OK; };
virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent) { return NS_OK; };
virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent) { return NS_OK; };
virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent) { return NS_OK; };
virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent) { return NS_OK; };
NS_IMETHOD Rollup();
NS_DECL_ISUPPORTS
NS_IMETHOD EnableListener(PRBool aEnabled);
void SetCurrentMenuParent(nsIMenuParent* aMenuParent);
NS_IMETHOD Unregister();
protected:
nsIMenuParent* mMenuParent;
nsIWidget* mWidget;
PRBool mEnabled;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,199 +0,0 @@
/* -*- 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.
*/
//
// nsMenuFrame
//
#ifndef nsMenuFrame_h__
#define nsMenuFrame_h__
#include "prtypes.h"
#include "nsIAtom.h"
#include "nsCOMPtr.h"
#include "nsIAnonymousContentCreator.h"
#include "nsBoxFrame.h"
#include "nsFrameList.h"
#include "nsIMenuParent.h"
#include "nsIMenuFrame.h"
#include "nsMenuDismissalListener.h"
#include "nsITimer.h"
#include "nsITimerCallback.h"
#include "nsISupportsArray.h"
#include "nsIDOMText.h"
#include "nsIContent.h"
nsresult NS_NewMenuFrame(nsIFrame** aResult, PRUint32 aFlags) ;
class nsMenuBarFrame;
class nsMenuPopupFrame;
class nsMenuFrame : public nsBoxFrame,
public nsIMenuFrame,
public nsITimerCallback,
public nsIAnonymousContentCreator
{
public:
nsMenuFrame();
NS_DECL_ISUPPORTS
// The nsIAnonymousContentCreator interface
NS_IMETHOD CreateAnonymousContent(nsISupportsArray& aAnonymousItems);
// The nsITimerCallback interface
virtual void Notify(nsITimer *timer);
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow);
NS_IMETHOD IsActive(PRBool& aResult) { aResult = PR_TRUE; return NS_OK; };
// The following four methods are all overridden so that the menu children
// can be stored in a separate list (so that they don't impact reflow of the
// actual menu item at all).
NS_IMETHOD FirstChild(nsIAtom* aListName,
nsIFrame** aFirstChild) const;
NS_IMETHOD SetInitialChildList(nsIPresContext& aPresContext,
nsIAtom* aListName,
nsIFrame* aChildList);
NS_IMETHOD GetAdditionalChildListName(PRInt32 aIndex,
nsIAtom** aListName) const;
NS_IMETHOD Destroy(nsIPresContext& aPresContext);
// Overridden to prevent events from ever going to children of the menu.
NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext,
const nsPoint& aPoint,
nsIFrame** aFrame);
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
// Reflow methods
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD DidReflow(nsIPresContext& aPresContext,
nsDidReflowStatus aStatus);
NS_IMETHOD Dirty(nsIPresContext& aPresContext, const nsHTMLReflowState& aReflowState, nsIFrame*& incrementalChild);
NS_IMETHOD AppendFrames(nsIPresContext& aPresContext,
nsIPresShell& aPresShell,
nsIAtom* aListName,
nsIFrame* aFrameList);
NS_IMETHOD InsertFrames(nsIPresContext& aPresContext,
nsIPresShell& aPresShell,
nsIAtom* aListName,
nsIFrame* aPrevFrame,
nsIFrame* aFrameList);
NS_IMETHOD RemoveFrame(nsIPresContext& aPresContext,
nsIPresShell& aPresShell,
nsIAtom* aListName,
nsIFrame* aOldFrame);
// nsIMenuFrame Interface
NS_IMETHOD ActivateMenu(PRBool aActivateFlag);
NS_IMETHOD SelectMenu(PRBool aActivateFlag);
NS_IMETHOD OpenMenu(PRBool aActivateFlag);
NS_IMETHOD MenuIsOpen(PRBool& aResult) { aResult = IsOpen(); return NS_OK; };
NS_IMETHOD MenuIsContainer(PRBool& aResult) { aResult = IsMenu(); return NS_OK; };
NS_IMETHOD MenuIsChecked(PRBool& aResult) { aResult = mChecked; return NS_OK; };
NS_IMETHOD SelectFirstItem();
NS_IMETHOD Escape(PRBool& aHandledFlag);
NS_IMETHOD Enter();
NS_IMETHOD ShortcutNavigation(PRUint32 aLetter, PRBool& aHandledFlag);
NS_IMETHOD KeyboardNavigation(PRUint32 aDirection, PRBool& aHandledFlag);
NS_IMETHOD GetMenuParent(nsIMenuParent** aResult) { NS_IF_ADDREF(mMenuParent); *aResult = mMenuParent; return NS_OK; };
NS_IMETHOD GetRadioGroupName(nsString &aName) { aName = mGroupName; return NS_OK; };
NS_IMETHOD GetMenuType(nsMenuType &aType) { aType = mType; return NS_OK; };
NS_IMETHOD MarkAsGenerated();
// nsMenuFrame methods
PRBool IsOpen() { return mMenuOpen; };
PRBool IsMenu();
PRBool IsDisabled();
PRBool IsGenerated();
NS_IMETHOD ToggleMenuState();
void SetIsMenu(PRBool aIsMenu) { mIsMenu = aIsMenu; };
protected:
static void UpdateDismissalListener(nsIMenuParent* aMenuParent);
void UpdateMenuType();
void UpdateMenuSpecialState();
void OpenMenuInternal(PRBool aActivateFlag);
void GetMenuChildrenElement(nsIContent** aResult);
// Called to split the accesskey attribute up based on the specified string.
void SplitOnShortcut(nsString& aBeforeString, nsString& aAccessString, nsString& aAfterString);
// Examines the key node and builds the accelerator.
void BuildAcceleratorText(nsString& aAccelString);
// Called to execute our command handler.
void Execute();
// Called as a hook just before the menu gets opened.
PRBool OnCreate();
// Called as a hook just before the menu goes away.
PRBool OnDestroy();
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint);
protected:
nsFrameList mPopupFrames;
PRPackedBool mIsMenu; // Whether or not we can even have children or not.
PRPackedBool mMenuOpen;
PRPackedBool mHasAnonymousContent; // Do we have anonymous content frames?
PRPackedBool mChecked; // if so, are we checked?
nsMenuType mType;
nsCOMPtr<nsIContent> mMenuText;
nsCOMPtr<nsIContent> mAccelText;
nsIMenuParent* mMenuParent; // Our parent menu.
nsCOMPtr<nsITimer> mOpenTimer;
nsIPresContext* mPresContext; // Our pres context.
nsString mGroupName;
public:
static nsMenuDismissalListener* mDismissalListener; // The listener that dismisses menus.
}; // class nsMenuFrame
#endif

View File

@@ -1,757 +0,0 @@
/* -*- 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 "nsMenuPopupFrame.h"
#include "nsXULAtoms.h"
#include "nsHTMLAtoms.h"
#include "nsIContent.h"
#include "prtypes.h"
#include "nsIAtom.h"
#include "nsIPresContext.h"
#include "nsIStyleContext.h"
#include "nsCSSRendering.h"
#include "nsINameSpaceManager.h"
#include "nsIViewManager.h"
#include "nsWidgetsCID.h"
#include "nsMenuFrame.h"
#include "nsIPopupSetFrame.h"
const PRInt32 kMaxZ = 0x7fffffff; //XXX: Shouldn't there be a define somewhere for MaxInt for PRInt32
static NS_DEFINE_IID(kIFrameIID, NS_IFRAME_IID);
// NS_NewMenuPopupFrame
//
// Wrapper for creating a new menu popup container
//
nsresult
NS_NewMenuPopupFrame(nsIFrame** aNewFrame)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsMenuPopupFrame* it = new nsMenuPopupFrame;
if ( !it )
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = it;
return NS_OK;
}
NS_IMETHODIMP_(nsrefcnt)
nsMenuPopupFrame::AddRef(void)
{
return NS_OK;
}
NS_IMETHODIMP_(nsrefcnt)
nsMenuPopupFrame::Release(void)
{
return NS_OK;
}
NS_IMETHODIMP nsMenuPopupFrame::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
*aInstancePtr = NULL;
if (aIID.Equals(nsIMenuParent::GetIID())) {
*aInstancePtr = (void*)(nsIMenuParent*) this;
NS_ADDREF_THIS();
return NS_OK;
}
return nsBoxFrame::QueryInterface(aIID, aInstancePtr);
}
//
// nsMenuPopupFrame cntr
//
nsMenuPopupFrame::nsMenuPopupFrame()
:mCurrentMenu(nsnull)
{
} // cntr
NS_IMETHODIMP
nsMenuPopupFrame::Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
// XXX Hack
mPresContext = &aPresContext;
// We default to being vertical.
nsString value;
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::align, value);
mHorizontal = PR_FALSE;
if (value.EqualsIgnoreCase("vertical"))
mHorizontal = PR_FALSE;
else if (value.EqualsIgnoreCase("horizontal"))
mHorizontal = PR_TRUE;
CreateViewForFrame(aPresContext, this, aContext, PR_TRUE);
// Now that we've made a view, remove it and insert it at the correct
// position in the view hierarchy (as the root view). We do this so that we
// can draw the menus outside the confines of the window.
nsIView* ourView;
GetView(&aPresContext, &ourView);
nsIFrame* parent;
aParent->GetParentWithView(&aPresContext, &parent);
nsIView* parentView;
parent->GetView(&aPresContext, &parentView);
nsCOMPtr<nsIViewManager> viewManager;
parentView->GetViewManager(*getter_AddRefs(viewManager));
// Remove the view from its old position.
viewManager->RemoveChild(parentView, ourView);
// Reinsert ourselves as the root view with a maximum z-index.
nsIView* rootView;
viewManager->GetRootView(rootView);
viewManager->InsertChild(rootView, ourView, kMaxZ);
// XXX Hack. Change our transparency to be non-transparent
// until the bug related to update of transparency on show/hide
// is fixed.
viewManager->SetViewContentTransparency(ourView, PR_FALSE);
// Create a widget for ourselves.
nsWidgetInitData widgetData;
ourView->SetZIndex(kMaxZ);
widgetData.mWindowType = eWindowType_popup;
widgetData.mBorderStyle = eBorderStyle_default;
// XXX make sure we are hidden (shouldn't this be done automatically?)
ourView->SetVisibility(nsViewVisibility_kHide);
#ifdef XP_MAC
printf("XP Popups: This is a nag to indicate that an inconsistent hack is being done on the Mac for popups.\n");
static NS_DEFINE_IID(kCPopupCID, NS_POPUP_CID);
ourView->CreateWidget(kCPopupCID, &widgetData, nsnull);
#else
static NS_DEFINE_IID(kCChildCID, NS_CHILD_CID);
ourView->CreateWidget(kCChildCID, &widgetData, nsnull);
#endif
return rv;
}
void
nsMenuPopupFrame::GetViewOffset(nsIViewManager* aManager, nsIView* aView,
nsPoint& aPoint)
{
aPoint.x = 0;
aPoint.y = 0;
nsIView *parent;
nsRect bounds;
parent = aView;
while (nsnull != parent) {
parent->GetBounds(bounds);
aPoint.x += bounds.x;
aPoint.y += bounds.y;
parent->GetParent(parent);
}
}
void
nsMenuPopupFrame::GetNearestEnclosingView(nsIPresContext* aPresContext, nsIFrame* aStartFrame, nsIView** aResult)
{
*aResult = nsnull;
aStartFrame->GetView(aPresContext, aResult);
if (!*aResult) {
nsIFrame* parent;
aStartFrame->GetParentWithView(aPresContext, &parent);
if (parent)
parent->GetView(aPresContext, aResult);
}
}
nsresult
nsMenuPopupFrame::SyncViewWithFrame(nsIPresContext& aPresContext,
PRBool aOnMenuBar,
nsIFrame* aFrame,
PRInt32 aXPos, PRInt32 aYPos)
{
nsPoint parentPos;
nsCOMPtr<nsIViewManager> viewManager;
//Get the nearest enclosing parent view to aFrame.
nsIView* parentView = nsnull;
GetNearestEnclosingView(&aPresContext, aFrame, &parentView);
if (!parentView)
return NS_OK;
parentView->GetViewManager(*getter_AddRefs(viewManager));
GetViewOffset(viewManager, parentView, parentPos);
nsIView* view = nsnull;
GetView(&aPresContext, &view);
nsIView* containingView = nsnull;
nsPoint offset;
aFrame->GetOffsetFromView(&aPresContext, offset, &containingView);
nsRect parentRect;
aFrame->GetRect(parentRect);
const nsStyleDisplay* disp;
GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&) disp);
PRBool viewIsVisible = (NS_STYLE_VISIBILITY_VISIBLE == disp->mVisible);
nsViewVisibility oldVisibility;
view->GetVisibility(oldVisibility);
PRBool viewWasVisible = (oldVisibility == nsViewVisibility_kShow);
if (viewWasVisible && (! viewIsVisible)) {
view->SetVisibility(nsViewVisibility_kHide);
}
viewManager->ResizeView(view, mRect.width, mRect.height);
if (aXPos != -1 || aYPos != -1) {
// Convert the screen coords to twips
float p2t;
aPresContext.GetScaledPixelsToTwips(&p2t);
PRInt32 xpos = NSIntPixelsToTwips(aXPos, p2t);
PRInt32 ypos = NSIntPixelsToTwips(aYPos, p2t);
viewManager->MoveViewTo(view, xpos, ypos);
}
else if (aOnMenuBar)
viewManager->MoveViewTo(view, parentPos.x + offset.x, parentPos.y + parentRect.height + offset.y );
else viewManager->MoveViewTo(view, parentPos.x + parentRect.width + offset.x, parentPos.y + offset.y );
if ((! viewWasVisible) && viewIsVisible) {
view->SetVisibility(nsViewVisibility_kShow);
}
return NS_OK;
}
NS_IMETHODIMP
nsMenuPopupFrame::DidReflow(nsIPresContext& aPresContext,
nsDidReflowStatus aStatus)
{
// Copied from nsContainerFrame reflow WITHOUT the call
// nsFrame::DidReflow(). nsFrame::DidReflow() will move us to the
// wrong place.
nsresult result = NS_OK; /* = nsFrame::DidReflow(aPresContext, aStatus) */
if (NS_FRAME_REFLOW_FINISHED == aStatus) {
// Apply DidReflow to each and every list that this frame implements
nsIAtom* listName = nsnull;
PRInt32 listIndex = 0;
do {
nsIFrame* kid;
FirstChild(listName, &kid);
while (nsnull != kid) {
kid->DidReflow(aPresContext, aStatus);
kid->GetNextSibling(&kid);
}
NS_IF_RELEASE(listName);
GetAdditionalChildListName(listIndex++, &listName);
} while(nsnull != listName);
}
NS_FRAME_TRACE_OUT("nsContainerFrame::DidReflow");
return result;
}
NS_IMETHODIMP
nsMenuPopupFrame::GetNextMenuItem(nsIMenuFrame* aStart, nsIMenuFrame** aResult)
{
nsIFrame* currFrame = nsnull;
nsIFrame* startFrame = nsnull;
if (aStart) {
aStart->QueryInterface(kIFrameIID, (void**)&currFrame);
if (currFrame) {
startFrame = currFrame;
currFrame->GetNextSibling(&currFrame);
}
}
else currFrame = mFrames.FirstChild();
while (currFrame) {
nsCOMPtr<nsIContent> current;
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
if (IsValidItem(current)) {
nsCOMPtr<nsIMenuFrame> menuFrame = do_QueryInterface(currFrame);
*aResult = menuFrame.get();
NS_IF_ADDREF(*aResult);
return NS_OK;
}
currFrame->GetNextSibling(&currFrame);
}
currFrame = mFrames.FirstChild();
// Still don't have anything. Try cycling from the beginning.
while (currFrame && currFrame != startFrame) {
nsCOMPtr<nsIContent> current;
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
if (IsValidItem(current)) {
nsCOMPtr<nsIMenuFrame> menuFrame = do_QueryInterface(currFrame);
*aResult = menuFrame.get();
NS_IF_ADDREF(*aResult);
return NS_OK;
}
currFrame->GetNextSibling(&currFrame);
}
// No luck. Just return our start value.
*aResult = aStart;
return NS_OK;
}
NS_IMETHODIMP
nsMenuPopupFrame::GetPreviousMenuItem(nsIMenuFrame* aStart, nsIMenuFrame** aResult)
{
nsIFrame* currFrame = nsnull;
nsIFrame* startFrame = nsnull;
if (aStart) {
aStart->QueryInterface(kIFrameIID, (void**)&currFrame);
if (currFrame) {
startFrame = currFrame;
currFrame = mFrames.GetPrevSiblingFor(currFrame);
}
}
else currFrame = mFrames.LastChild();
while (currFrame) {
nsCOMPtr<nsIContent> current;
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
if (IsValidItem(current)) {
nsCOMPtr<nsIMenuFrame> menuFrame = do_QueryInterface(currFrame);
*aResult = menuFrame.get();
NS_IF_ADDREF(*aResult);
return NS_OK;
}
currFrame = mFrames.GetPrevSiblingFor(currFrame);
}
currFrame = mFrames.LastChild();
// Still don't have anything. Try cycling from the end.
while (currFrame && currFrame != startFrame) {
nsCOMPtr<nsIContent> current;
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
if (IsValidItem(current)) {
nsCOMPtr<nsIMenuFrame> menuFrame = do_QueryInterface(currFrame);
*aResult = menuFrame.get();
NS_IF_ADDREF(*aResult);
return NS_OK;
}
currFrame = mFrames.GetPrevSiblingFor(currFrame);
}
// No luck. Just return our start value.
*aResult = aStart;
return NS_OK;
}
NS_IMETHODIMP nsMenuPopupFrame::SetCurrentMenuItem(nsIMenuFrame* aMenuItem)
{
if (mCurrentMenu == aMenuItem)
return NS_OK;
// Unset the current child.
if (mCurrentMenu) {
PRBool isOpen = PR_FALSE;
mCurrentMenu->MenuIsOpen(isOpen);
mCurrentMenu->SelectMenu(PR_FALSE);
if (isOpen)
mCurrentMenu->OpenMenu(PR_FALSE);
}
// Set the new child.
if (aMenuItem) {
aMenuItem->SelectMenu(PR_TRUE);
}
mCurrentMenu = aMenuItem;
return NS_OK;
}
NS_IMETHODIMP
nsMenuPopupFrame::CaptureMouseEvents(nsIPresContext* aPresContext, PRBool aGrabMouseEvents)
{
// get its view
nsIView* view = nsnull;
GetView(aPresContext, &view);
nsCOMPtr<nsIViewManager> viewMan;
PRBool result;
nsCOMPtr<nsIWidget> widget;
if (view) {
view->GetViewManager(*getter_AddRefs(viewMan));
if (viewMan) {
view->GetWidget(*getter_AddRefs(widget));
if (aGrabMouseEvents) {
viewMan->GrabMouseEvents(view,result);
mIsCapturingMouseEvents = PR_TRUE;
//widget->CaptureMouse(PR_TRUE);
} else {
viewMan->GrabMouseEvents(nsnull,result);
mIsCapturingMouseEvents = PR_FALSE;
//widget->CaptureMouse(PR_FALSE);
}
}
}
return NS_OK;
}
void
nsMenuPopupFrame::Escape(PRBool& aHandledFlag)
{
if (!mCurrentMenu)
return;
// See if our menu is open.
PRBool isOpen = PR_FALSE;
mCurrentMenu->MenuIsOpen(isOpen);
if (isOpen) {
// Let the child menu handle this.
mCurrentMenu->Escape(aHandledFlag);
if (!aHandledFlag) {
// We should close up.
mCurrentMenu->OpenMenu(PR_FALSE);
aHandledFlag = PR_TRUE;
}
return;
}
}
void
nsMenuPopupFrame::Enter()
{
// Give it to the child.
if (mCurrentMenu)
mCurrentMenu->Enter();
}
nsIMenuFrame*
nsMenuPopupFrame::FindMenuWithShortcut(PRUint32 aLetter)
{
// Enumerate over our list of frames.
nsIFrame* currFrame = mFrames.FirstChild();
while (currFrame) {
nsCOMPtr<nsIContent> current;
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
if (IsValidItem(current)) {
// Get the shortcut attribute.
nsString shortcutKey = "";
current->GetAttribute(kNameSpaceID_None, nsXULAtoms::accesskey, shortcutKey);
shortcutKey.ToUpperCase();
if (shortcutKey.Length() > 0) {
// We've got something.
PRUnichar shortcutChar = shortcutKey.CharAt(0);
if (shortcutChar == aLetter) {
// We match!
nsCOMPtr<nsIMenuFrame> menuFrame = do_QueryInterface(currFrame);
if (menuFrame)
return menuFrame.get();
return nsnull;
}
}
}
currFrame->GetNextSibling(&currFrame);
}
return nsnull;
}
void
nsMenuPopupFrame::ShortcutNavigation(PRUint32 aLetter, PRBool& aHandledFlag)
{
if (mCurrentMenu) {
PRBool isOpen = PR_FALSE;
mCurrentMenu->MenuIsOpen(isOpen);
if (isOpen) {
// No way this applies to us. Give it to our child.
mCurrentMenu->ShortcutNavigation(aLetter, aHandledFlag);
return;
}
}
// This applies to us. Let's see if one of the shortcuts applies
nsIMenuFrame* result = FindMenuWithShortcut(aLetter);
if (result) {
// We got one!
aHandledFlag = PR_TRUE;
SetCurrentMenuItem(result);
result->OpenMenu(PR_TRUE);
result->SelectFirstItem();
// XXX For menu items, do an execution of the oncommand handler!
// Still needed or did I do this already? I'm going senile. - Dave
}
}
void
nsMenuPopupFrame::KeyboardNavigation(PRUint32 aDirection, PRBool& aHandledFlag)
{
// This method only gets called if we're open.
if (!mCurrentMenu && (aDirection == NS_VK_RIGHT || aDirection == NS_VK_LEFT)) {
// We've been opened, but we haven't had anything selected.
// We can handle RIGHT, but our parent handles LEFT.
if (aDirection == NS_VK_RIGHT) {
nsIMenuFrame* nextItem;
GetNextMenuItem(nsnull, &nextItem);
if (nextItem) {
aHandledFlag = PR_TRUE;
SetCurrentMenuItem(nextItem);
}
}
return;
}
PRBool isContainer = PR_FALSE;
PRBool isOpen = PR_FALSE;
if (mCurrentMenu) {
mCurrentMenu->MenuIsContainer(isContainer);
mCurrentMenu->MenuIsOpen(isOpen);
if (isOpen) {
// Give our child a shot.
mCurrentMenu->KeyboardNavigation(aDirection, aHandledFlag);
}
else if (aDirection == NS_VK_RIGHT && isContainer) {
// The menu is not yet open. Open it and select the first item.
aHandledFlag = PR_TRUE;
mCurrentMenu->OpenMenu(PR_TRUE);
mCurrentMenu->SelectFirstItem();
}
}
if (aHandledFlag)
return; // The child menu took it for us.
// For the vertical direction, we can move up or down.
if (aDirection == NS_VK_UP || aDirection == NS_VK_DOWN) {
nsIMenuFrame* nextItem;
if (aDirection == NS_VK_DOWN)
GetNextMenuItem(mCurrentMenu, &nextItem);
else GetPreviousMenuItem(mCurrentMenu, &nextItem);
SetCurrentMenuItem(nextItem);
aHandledFlag = PR_TRUE;
}
else if (mCurrentMenu && isContainer && isOpen) {
if (aDirection == NS_VK_LEFT) {
// Close it up.
mCurrentMenu->OpenMenu(PR_FALSE);
aHandledFlag = PR_TRUE;
}
}
}
NS_IMETHODIMP
nsMenuPopupFrame::GetParentPopup(nsIMenuParent** aMenuParent)
{
*aMenuParent = nsnull;
nsIFrame* frame;
GetParent(&frame);
if (frame) {
nsIFrame* grandparent;
frame->GetParent(&grandparent);
if (grandparent) {
nsCOMPtr<nsIMenuParent> menuParent = do_QueryInterface(grandparent);
if (menuParent) {
*aMenuParent = menuParent.get();
NS_ADDREF(*aMenuParent);
}
}
}
return NS_OK;
}
NS_IMETHODIMP
nsMenuPopupFrame::HideChain()
{
// Stop capturing rollups
// (must do this during Hide, which happens before the menu item is executed,
// since this reinstates normal event handling.)
if (nsMenuFrame::mDismissalListener)
nsMenuFrame::mDismissalListener->Unregister();
nsIFrame* frame;
GetParent(&frame);
if (frame) {
nsCOMPtr<nsIPopupSetFrame> popupSetFrame = do_QueryInterface(frame);
if (popupSetFrame) {
// Destroy the popup.
popupSetFrame->HidePopup();
return NS_OK;
}
nsCOMPtr<nsIMenuFrame> menuFrame = do_QueryInterface(frame);
if (!menuFrame)
return NS_OK;
menuFrame->ActivateMenu(PR_FALSE);
menuFrame->SelectMenu(PR_FALSE);
// Get the parent.
nsCOMPtr<nsIMenuParent> menuParent;
menuFrame->GetMenuParent(getter_AddRefs(menuParent));
if (menuParent)
menuParent->HideChain();
}
return NS_OK;
}
NS_IMETHODIMP
nsMenuPopupFrame::DismissChain()
{
// Stop capturing rollups
if (nsMenuFrame::mDismissalListener)
nsMenuFrame::mDismissalListener->Unregister();
// Get our menu parent.
nsIFrame* frame;
GetParent(&frame);
if (frame) {
nsCOMPtr<nsIPopupSetFrame> popupSetFrame = do_QueryInterface(frame);
if (popupSetFrame) {
// Destroy the popup.
popupSetFrame->DestroyPopup();
return NS_OK;
}
nsCOMPtr<nsIMenuFrame> menuFrame = do_QueryInterface(frame);
if (!menuFrame)
return NS_OK;
menuFrame->OpenMenu(PR_FALSE);
// Get the parent.
nsCOMPtr<nsIMenuParent> menuParent;
menuFrame->GetMenuParent(getter_AddRefs(menuParent));
if (menuParent)
menuParent->DismissChain();
}
return NS_OK;
}
NS_IMETHODIMP
nsMenuPopupFrame::GetWidget(nsIWidget **aWidget)
{
// Get parent view
nsIView * view = nsnull;
nsMenuPopupFrame::GetNearestEnclosingView(mPresContext, this, &view);
if (!view)
return NS_OK;
view->GetWidget(*aWidget);
return NS_OK;
}
NS_IMETHODIMP
nsMenuPopupFrame::CreateDismissalListener()
{
nsMenuDismissalListener *listener = new nsMenuDismissalListener();
if (!listener) return NS_ERROR_OUT_OF_MEMORY;
nsMenuFrame::mDismissalListener = listener;
NS_ADDREF(listener);
return NS_OK;
}
PRBool
nsMenuPopupFrame::IsValidItem(nsIContent* aContent)
{
nsCOMPtr<nsIAtom> tag;
aContent->GetTag(*getter_AddRefs(tag));
if (tag && (tag.get() == nsXULAtoms::menu ||
tag.get() == nsXULAtoms::menuitem) &&
!IsDisabled(aContent))
return PR_TRUE;
return PR_FALSE;
}
PRBool
nsMenuPopupFrame::IsDisabled(nsIContent* aContent)
{
nsString disabled = "";
aContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, disabled);
if (disabled == "true")
return PR_TRUE;
return PR_FALSE;
}
NS_IMETHODIMP
nsMenuPopupFrame::HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
}
NS_IMETHODIMP
nsMenuPopupFrame::Destroy(nsIPresContext& aPresContext)
{
//nsCOMPtr<nsIDOMEventReceiver> target = do_QueryInterface(mContent);
//target->RemoveEventListener("mousemove", mMenuPopupEntryListener, PR_TRUE);
return nsBoxFrame::Destroy(aPresContext);
}
NS_IMETHODIMP
nsMenuPopupFrame::GetFrameForPoint(nsIPresContext* aPresContext,
const nsPoint& aPoint,
nsIFrame** aFrame)
{
nsRect rect;
GetRect(rect);
if (rect.Contains(aPoint)) {
return nsBoxFrame::GetFrameForPoint(aPresContext, aPoint, aFrame);
}
*aFrame = this;
return NS_OK;
}

View File

@@ -1,113 +0,0 @@
/* -*- 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.
*/
//
// nsMenuPopupFrame
//
#ifndef nsMenuPopupFrame_h__
#define nsMenuPopupFrame_h__
#include "prtypes.h"
#include "nsIAtom.h"
#include "nsCOMPtr.h"
#include "nsBoxFrame.h"
#include "nsIMenuParent.h"
#include "nsIWidget.h"
nsresult NS_NewMenuPopupFrame(nsIFrame** aResult) ;
class nsIViewManager;
class nsIView;
class nsIMenuParent;
class nsIMenuFrame;
class nsMenuPopupFrame : public nsBoxFrame, public nsIMenuParent
{
public:
nsMenuPopupFrame();
NS_DECL_ISUPPORTS
// nsIMenuParentInterface
NS_IMETHOD SetCurrentMenuItem(nsIMenuFrame* aMenuItem);
NS_IMETHOD GetNextMenuItem(nsIMenuFrame* aStart, nsIMenuFrame** aResult);
NS_IMETHOD GetPreviousMenuItem(nsIMenuFrame* aStart, nsIMenuFrame** aResult);
NS_IMETHOD SetActive(PRBool aActiveFlag) { return NS_OK; }; // We don't care.
NS_IMETHOD GetIsActive(PRBool& isActive) { isActive = PR_FALSE; return NS_OK; };
NS_IMETHOD IsMenuBar(PRBool& isMenuBar) { isMenuBar = PR_FALSE; return NS_OK; };
NS_IMETHOD GetParentPopup(nsIMenuParent** aResult);
// Closes up the chain of open cascaded menus.
NS_IMETHOD DismissChain();
// Hides the chain of cascaded menus without closing them up.
NS_IMETHOD HideChain();
NS_IMETHOD GetWidget(nsIWidget **aWidget);
// The dismissal listener gets created and attached to the window.
NS_IMETHOD CreateDismissalListener();
// Overridden methods
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow);
NS_IMETHOD DidReflow(nsIPresContext& aPresContext,
nsDidReflowStatus aStatus);
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD Destroy(nsIPresContext& aPresContext);
NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext, const nsPoint& aPoint, nsIFrame** aFrame);
void GetViewOffset(nsIViewManager* aManager, nsIView* aView, nsPoint& aPoint);
static void GetNearestEnclosingView(nsIPresContext* aPresContext, nsIFrame* aStartFrame, nsIView** aResult);
nsresult SyncViewWithFrame(nsIPresContext& aPresContext, PRBool aOnMenuBar,
nsIFrame* aFrame, PRInt32 aXPos, PRInt32 aYPos);
NS_IMETHOD CaptureMouseEvents(nsIPresContext* aPresContext, PRBool aGrabMouseEvents);
void KeyboardNavigation(PRUint32 aDirection, PRBool& aHandledFlag);
void ShortcutNavigation(PRUint32 aLetter, PRBool& aHandledFlag);
nsIMenuFrame* FindMenuWithShortcut(PRUint32 aLetter);
void Escape(PRBool& aHandledFlag);
void Enter();
PRBool IsValidItem(nsIContent* aContent);
PRBool IsDisabled(nsIContent* aContent);
protected:
nsIMenuFrame* mCurrentMenu; // The current menu that is active.
PRBool mIsCapturingMouseEvents; // Whether or not we're grabbing the mouse events.
// XXX Hack
nsIPresContext* mPresContext; // weak reference
}; // class nsMenuPopupFrame
#endif

View File

@@ -1,547 +0,0 @@
/* -*- 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 "nsXULAtoms.h"
#include "nsHTMLAtoms.h"
#include "nsPopupSetFrame.h"
#include "nsIMenuParent.h"
#include "nsMenuFrame.h"
#include "nsBoxFrame.h"
#include "nsIContent.h"
#include "prtypes.h"
#include "nsIAtom.h"
#include "nsIPresContext.h"
#include "nsIStyleContext.h"
#include "nsIReflowCommand.h"
#include "nsCSSRendering.h"
#include "nsINameSpaceManager.h"
#include "nsLayoutAtoms.h"
#include "nsMenuPopupFrame.h"
#include "nsMenuBarFrame.h"
#include "nsIView.h"
#include "nsIWidget.h"
#include "nsIDocument.h"
#include "nsIDOMNSDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMXULDocument.h"
#include "nsIDOMElement.h"
#include "nsISupportsArray.h"
#include "nsIDOMText.h"
#define NS_MENU_POPUP_LIST_INDEX (NS_AREA_FRAME_ABSOLUTE_LIST_INDEX + 1)
//
// NS_NewPopupSetFrame
//
// Wrapper for creating a new menu popup container
//
nsresult
NS_NewPopupSetFrame(nsIFrame** aNewFrame)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsPopupSetFrame* it = new nsPopupSetFrame;
if ( !it )
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = it;
return NS_OK;
}
NS_IMETHODIMP_(nsrefcnt)
nsPopupSetFrame::AddRef(void)
{
return NS_OK;
}
NS_IMETHODIMP_(nsrefcnt)
nsPopupSetFrame::Release(void)
{
return NS_OK;
}
NS_IMETHODIMP nsPopupSetFrame::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
*aInstancePtr = NULL;
if (aIID.Equals(nsIPopupSetFrame::GetIID())) {
*aInstancePtr = (void*)(nsIPopupSetFrame*) this;
NS_ADDREF_THIS();
return NS_OK;
}
return nsBoxFrame::QueryInterface(aIID, aInstancePtr);
}
//
// nsPopupSetFrame cntr
//
nsPopupSetFrame::nsPopupSetFrame()
:mPresContext(nsnull), mElementFrame(nsnull)
{
} // cntr
nsIFrame*
nsPopupSetFrame::GetActiveChild()
{
return mPopupFrames.FirstChild();
}
NS_IMETHODIMP
nsPopupSetFrame::Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
mPresContext = &aPresContext; // Don't addref it. Our lifetime is shorter.
nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
return rv;
}
// The following methods are all overridden to ensure that the menupopup frames
// are placed in the appropriate list.
NS_IMETHODIMP
nsPopupSetFrame::FirstChild(nsIAtom* aListName,
nsIFrame** aFirstChild) const
{
if (nsLayoutAtoms::popupList == aListName) {
*aFirstChild = mPopupFrames.FirstChild();
} else {
nsBoxFrame::FirstChild(aListName, aFirstChild);
}
return NS_OK;
}
NS_IMETHODIMP
nsPopupSetFrame::SetInitialChildList(nsIPresContext& aPresContext,
nsIAtom* aListName,
nsIFrame* aChildList)
{
nsresult rv = NS_OK;
if (nsLayoutAtoms::popupList == aListName) {
mPopupFrames.SetFrames(aChildList);
} else {
nsFrameList frames(aChildList);
// We may have menupopups in here. Get them out, and move them into
// the popup frame list.
nsIFrame* frame = frames.FirstChild();
while (frame) {
nsCOMPtr<nsIContent> content;
frame->GetContent(getter_AddRefs(content));
nsCOMPtr<nsIAtom> tag;
content->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::popup) {
// Remove this frame from the list and place it in the other list.
frames.RemoveFrame(frame);
mPopupFrames.AppendFrame(this, frame);
nsIFrame* first = frames.FirstChild();
rv = nsBoxFrame::SetInitialChildList(aPresContext, aListName, first);
return rv;
}
frame->GetNextSibling(&frame);
}
// Didn't find it.
rv = nsBoxFrame::SetInitialChildList(aPresContext, aListName, aChildList);
}
return rv;
}
NS_IMETHODIMP
nsPopupSetFrame::GetAdditionalChildListName(PRInt32 aIndex,
nsIAtom** aListName) const
{
// Maintain a separate child list for the menu contents.
// This is necessary because we don't want the menu contents to be included in the layout
// of the menu's single item because it would take up space, when it is supposed to
// be floating above the display.
/*NS_PRECONDITION(nsnull != aListName, "null OUT parameter pointer");
*aListName = nsnull;
if (NS_MENU_POPUP_LIST_INDEX == aIndex) {
*aListName = nsLayoutAtoms::popupList;
NS_ADDREF(*aListName);
return NS_OK;
}*/
return nsBoxFrame::GetAdditionalChildListName(aIndex, aListName);
}
NS_IMETHODIMP
nsPopupSetFrame::Destroy(nsIPresContext& aPresContext)
{
// Cleanup frames in popup child list
mPopupFrames.DestroyFrames(aPresContext);
return nsBoxFrame::Destroy(aPresContext);
}
NS_IMETHODIMP
nsPopupSetFrame::Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
nsresult rv = nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
nsIFrame* frame = GetActiveChild();
if (!frame || (rv != NS_OK))
return rv;
// Constrain the child's width and height to aAvailableWidth and aAvailableHeight
nsSize availSize(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, frame,
availSize);
kidReflowState.mComputedWidth = NS_UNCONSTRAINEDSIZE;
kidReflowState.mComputedHeight = NS_UNCONSTRAINEDSIZE;
// Reflow child
nscoord w = aDesiredSize.width;
nscoord h = aDesiredSize.height;
rv = ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, aStatus);
// Set the child's width and height to its desired size
nsRect rect;
frame->GetRect(rect);
rect.width = aDesiredSize.width;
rect.height = aDesiredSize.height;
frame->SetRect(&aPresContext, rect);
// Don't let it affect our size.
aDesiredSize.width = w;
aDesiredSize.height = h;
return rv;
}
NS_IMETHODIMP
nsPopupSetFrame::DidReflow(nsIPresContext& aPresContext,
nsDidReflowStatus aStatus)
{
// Sync up the view.
nsIFrame* activeChild = GetActiveChild();
if (activeChild) {
((nsMenuPopupFrame*)activeChild)->SyncViewWithFrame(aPresContext, PR_TRUE, mElementFrame, mXPos, mYPos);
}
return nsBoxFrame::DidReflow(aPresContext, aStatus);
}
// Overridden Box method.
NS_IMETHODIMP
nsPopupSetFrame::Dirty(nsIPresContext& aPresContext, const nsHTMLReflowState& aReflowState, nsIFrame*& incrementalChild)
{
incrementalChild = nsnull;
nsresult rv = NS_OK;
// Dirty any children that need it.
nsIFrame* frame;
aReflowState.reflowCommand->GetNext(frame, PR_FALSE);
if (frame == nsnull) {
incrementalChild = this;
return rv;
}
// Now call our original box frame method
rv = nsBoxFrame::Dirty(aPresContext, aReflowState, incrementalChild);
if (rv != NS_OK || incrementalChild)
return rv;
nsIFrame* popup = GetActiveChild();
if (popup && (frame == popup)) {
// An incremental reflow command is targeting something inside our
// hidden popup view. We can't actually return the child, since it
// won't ever be found by box. Instead return ourselves, so that box
// will later send us an incremental reflow command.
incrementalChild = this;
// In order for the child box to know what it needs to reflow, we need
// to call its Dirty method...
nsIFrame* ignore;
nsIBox* ibox;
if (NS_SUCCEEDED(popup->QueryInterface(nsIBox::GetIID(), (void**)&ibox)) && ibox)
ibox->Dirty(aPresContext, aReflowState, ignore);
}
return rv;
}
NS_IMETHODIMP
nsPopupSetFrame::RemoveFrame(nsIPresContext& aPresContext,
nsIPresShell& aPresShell,
nsIAtom* aListName,
nsIFrame* aOldFrame)
{
// need to rebuild all the springs.
for (int i=0; i < mSpringCount; i++)
mSprings[i].clear();
nsresult rv;
if (mPopupFrames.ContainsFrame(aOldFrame)) {
// Go ahead and remove this frame.
mPopupFrames.DestroyFrame(aPresContext, aOldFrame);
rv = GenerateDirtyReflowCommand(aPresContext, aPresShell);
} else {
rv = nsBoxFrame::RemoveFrame(aPresContext, aPresShell, aListName, aOldFrame);
}
return rv;
}
NS_IMETHODIMP
nsPopupSetFrame::InsertFrames(nsIPresContext& aPresContext,
nsIPresShell& aPresShell,
nsIAtom* aListName,
nsIFrame* aPrevFrame,
nsIFrame* aFrameList)
{
// need to rebuild all the springs.
for (int i=0; i < mSpringCount; i++)
mSprings[i].clear();
nsCOMPtr<nsIContent> frameChild;
aFrameList->GetContent(getter_AddRefs(frameChild));
nsCOMPtr<nsIAtom> tag;
nsresult rv;
frameChild->GetTag(*getter_AddRefs(tag));
if (tag && tag.get() == nsXULAtoms::popup) {
mPopupFrames.InsertFrames(nsnull, nsnull, aFrameList);
rv = GenerateDirtyReflowCommand(aPresContext, aPresShell);
} else {
rv = nsBoxFrame::InsertFrames(aPresContext, aPresShell, aListName, aPrevFrame, aFrameList);
}
return rv;
}
NS_IMETHODIMP
nsPopupSetFrame::AppendFrames(nsIPresContext& aPresContext,
nsIPresShell& aPresShell,
nsIAtom* aListName,
nsIFrame* aFrameList)
{
if (!aFrameList)
return NS_OK;
// need to rebuild all the springs.
for (int i=0; i < mSpringCount; i++)
mSprings[i].clear();
nsCOMPtr<nsIContent> frameChild;
aFrameList->GetContent(getter_AddRefs(frameChild));
nsCOMPtr<nsIAtom> tag;
nsresult rv;
frameChild->GetTag(*getter_AddRefs(tag));
if (tag && tag.get() == nsXULAtoms::popup) {
mPopupFrames.AppendFrames(nsnull, aFrameList);
rv = GenerateDirtyReflowCommand(aPresContext, aPresShell);
} else {
rv = nsBoxFrame::AppendFrames(aPresContext, aPresShell, aListName, aFrameList);
}
return rv;
}
NS_IMETHODIMP
nsPopupSetFrame::CreatePopup(nsIFrame* aElementFrame, nsIContent* aPopupContent,
PRInt32 aXPos, PRInt32 aYPos,
const nsString& aPopupType, const nsString& anAnchorAlignment,
const nsString& aPopupAlignment)
{
// Cache the element frame.
mElementFrame = aElementFrame;
// Show the popup at the specified position.
mXPos = aXPos;
mYPos = aYPos;
printf("X Pos: %d\n", mXPos);
printf("Y Pos: %d\n", mYPos);
if (!OnCreate(aPopupContent))
return NS_OK;
// Generate the popup.
MarkAsGenerated(aPopupContent);
// Now we'll have it in our child frame list.
// Now open the popup.
OpenPopup(PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP
nsPopupSetFrame::HidePopup()
{
ActivatePopup(PR_FALSE);
return NS_OK;
}
NS_IMETHODIMP
nsPopupSetFrame::DestroyPopup()
{
OpenPopup(PR_FALSE);
return NS_OK;
}
void
nsPopupSetFrame::MarkAsGenerated(nsIContent* aPopupContent)
{
// Ungenerate all other popups in the set. No more than one can exist
// at any point in time.
PRInt32 childCount;
mContent->ChildCount(childCount);
for (PRInt32 i = 0; i < childCount; i++) {
nsCOMPtr<nsIContent> childContent;
mContent->ChildAt(i, *getter_AddRefs(childContent));
// Retrieve the menugenerated attribute.
nsAutoString value;
childContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::menugenerated,
value);
if (value == "true") {
// Ungenerate this element.
childContent->UnsetAttribute(kNameSpaceID_None, nsXULAtoms::menugenerated,
PR_TRUE);
}
}
// Set our attribute, but only if we aren't already generated.
// Retrieve the menugenerated attribute.
nsAutoString value;
aPopupContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::menugenerated,
value);
if (value != "true") {
// Generate this element.
aPopupContent->SetAttribute(kNameSpaceID_None, nsXULAtoms::menugenerated, "true",
PR_TRUE);
}
}
void
nsPopupSetFrame::OpenPopup(PRBool aActivateFlag)
{
if (aActivateFlag) {
ActivatePopup(PR_TRUE);
nsIFrame* activeChild = GetActiveChild();
nsCOMPtr<nsIMenuParent> childPopup = do_QueryInterface(activeChild);
UpdateDismissalListener(childPopup);
}
else {
if (!OnDestroy())
return;
// Unregister.
if (nsMenuFrame::mDismissalListener) {
nsMenuFrame::mDismissalListener->Unregister();
}
ActivatePopup(PR_FALSE);
}
}
void
nsPopupSetFrame::ActivatePopup(PRBool aActivateFlag)
{
nsCOMPtr<nsIContent> content;
GetActiveChildElement(getter_AddRefs(content));
if (content) {
if (aActivateFlag)
content->SetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, "true", PR_TRUE);
else content->UnsetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, PR_TRUE);
}
}
PRBool
nsPopupSetFrame::OnCreate(nsIContent* aPopupContent)
{
nsEventStatus status = nsEventStatus_eIgnore;
nsMouseEvent event;
event.eventStructType = NS_EVENT;
event.message = NS_MENU_CREATE;
if (aPopupContent) {
nsresult rv = aPopupContent->HandleDOMEvent(*mPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
return PR_FALSE;
}
return PR_TRUE;
}
PRBool
nsPopupSetFrame::OnDestroy()
{
nsEventStatus status = nsEventStatus_eIgnore;
nsMouseEvent event;
event.eventStructType = NS_EVENT;
event.message = NS_MENU_DESTROY;
nsCOMPtr<nsIContent> content;
GetActiveChildElement(getter_AddRefs(content));
if (content) {
nsresult rv = content->HandleDOMEvent(*mPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
return PR_FALSE;
}
return PR_TRUE;
}
void
nsPopupSetFrame::GetActiveChildElement(nsIContent** aResult)
{
*aResult = nsnull;
nsIFrame* child = GetActiveChild();
if (child) {
child->GetContent(aResult);
}
}
void
nsPopupSetFrame::UpdateDismissalListener(nsIMenuParent* aMenuParent)
{
if (!nsMenuFrame::mDismissalListener) {
if (!aMenuParent)
return;
// Create the listener and attach it to the outermost window.
aMenuParent->CreateDismissalListener();
}
// Make sure the menu dismissal listener knows what the current
// innermost menu popup frame is.
nsMenuFrame::mDismissalListener->SetCurrentMenuParent(aMenuParent);
}

View File

@@ -1,125 +0,0 @@
/* -*- 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.
*/
//
// nsPopupSetFrame
//
#ifndef nsPopupSetFrame_h__
#define nsPopupSetFrame_h__
#include "prtypes.h"
#include "nsIAtom.h"
#include "nsCOMPtr.h"
#include "nsIPopupSetFrame.h"
#include "nsIAnonymousContentCreator.h"
#include "nsBoxFrame.h"
#include "nsFrameList.h"
#include "nsIMenuParent.h"
#include "nsITimer.h"
#include "nsITimerCallback.h"
#include "nsISupportsArray.h"
nsresult NS_NewPopupSetFrame(nsIFrame** aResult) ;
class nsPopupSetFrame : public nsBoxFrame, public nsIPopupSetFrame
{
public:
nsPopupSetFrame();
NS_DECL_ISUPPORTS
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow);
// The following four methods are all overridden so that the menu children
// can be stored in a separate list (so that they don't impact reflow of the
// actual menu item at all).
NS_IMETHOD FirstChild(nsIAtom* aListName,
nsIFrame** aFirstChild) const;
NS_IMETHOD SetInitialChildList(nsIPresContext& aPresContext,
nsIAtom* aListName,
nsIFrame* aChildList);
NS_IMETHOD GetAdditionalChildListName(PRInt32 aIndex,
nsIAtom** aListName) const;
NS_IMETHOD Destroy(nsIPresContext& aPresContext);
// Reflow methods
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD DidReflow(nsIPresContext& aPresContext,
nsDidReflowStatus aStatus);
NS_IMETHOD Dirty(nsIPresContext& aPresContext, const nsHTMLReflowState& aReflowState, nsIFrame*& incrementalChild);
NS_IMETHOD AppendFrames(nsIPresContext& aPresContext,
nsIPresShell& aPresShell,
nsIAtom* aListName,
nsIFrame* aFrameList);
NS_IMETHOD InsertFrames(nsIPresContext& aPresContext,
nsIPresShell& aPresShell,
nsIAtom* aListName,
nsIFrame* aPrevFrame,
nsIFrame* aFrameList);
NS_IMETHOD RemoveFrame(nsIPresContext& aPresContext,
nsIPresShell& aPresShell,
nsIAtom* aListName,
nsIFrame* aOldFrame);
NS_IMETHOD CreatePopup(nsIFrame* aElementFrame, nsIContent* aPopupContent,
PRInt32 aXPos, PRInt32 aYPos,
const nsString& aPopupType, const nsString& anAnchorAlignment,
const nsString& aPopupAlignment);
NS_IMETHOD HidePopup();
NS_IMETHOD DestroyPopup();
PRBool OnCreate(nsIContent* aPopupContent);
PRBool OnDestroy();
void ActivatePopup(PRBool aActivateFlag);
void OpenPopup(PRBool aOpenFlag);
nsIFrame* GetActiveChild();
void GetActiveChildElement(nsIContent** aResult);
protected:
void MarkAsGenerated(nsIContent* aPopupContent);
void UpdateDismissalListener(nsIMenuParent* aMenuParent);
protected:
nsFrameList mPopupFrames;
nsIPresContext* mPresContext; // Our pres context.
nsIFrame* mElementFrame; // The frame that is having something popped up over it.
PRInt32 mXPos; // Active child's x position
PRInt32 mYPos; // Active child's y position
}; // class nsPopupSetFrame
#endif

View File

@@ -1,813 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
//
// Eric Vaughan
// Netscape Communications
//
// See documentation in associated header file
//
static float STRIPE_SKEW = 1.0; // pixels
static int STRIPE_WIDTH = 20; // pixels
static int ANIMATION_INCREMENT = 4; // pixels
static int ANIMATION_SPEED = 50; // miliseconds
#include "nsINameSpaceManager.h"
#include "nsProgressMeterFrame.h"
#include "nsIStyleContext.h"
#include "nsCSSRendering.h"
#include "nsIContent.h"
#include "nsIPresContext.h"
#include "nsHTMLAtoms.h"
#include "nsXULAtoms.h"
#include "nsINameSpaceManager.h"
#include "nsITimerCallback.h"
#include "nsITimer.h"
#include "nsIView.h"
#include "nsIViewManager.h"
#include "nsIReflowCommand.h"
#include "nsHTMLParts.h"
#include "nsIPresShell.h"
class StripeTimer : public nsITimerCallback {
public:
StripeTimer();
virtual ~StripeTimer();
NS_DECL_ISUPPORTS
void AddFrame(nsIPresContext* aPresContext, nsProgressMeterFrame* aFrame);
PRBool RemoveFrame(nsProgressMeterFrame* aFrame);
PRInt32 FrameCount();
void Start();
void Stop();
virtual void Notify(nsITimer *timer);
PRInt32 GetFrameData(nsProgressMeterFrame* aFrame);
struct FrameData {
nsIPresContext* mPresContext; // pres context associated with the frame
nsProgressMeterFrame* mFrame;
FrameData(nsIPresContext* aPresContext,
nsProgressMeterFrame* aFrame)
: mPresContext(aPresContext), mFrame(aFrame) {}
};
nsITimer* mTimer;
nsVoidArray mFrames;
};
static StripeTimer* gStripeAnimator;
StripeTimer::StripeTimer()
{
NS_INIT_REFCNT();
mTimer = nsnull;
}
StripeTimer::~StripeTimer()
{
Stop();
}
void StripeTimer::Start()
{
nsresult rv = NS_NewTimer(&mTimer);
if (NS_OK == rv) {
mTimer->Init(this, ANIMATION_SPEED);
}
}
void StripeTimer::Stop()
{
if (nsnull != mTimer) {
mTimer->Cancel();
NS_RELEASE(mTimer);
}
}
static NS_DEFINE_IID(kITimerCallbackIID, NS_ITIMERCALLBACK_IID);
NS_IMPL_ISUPPORTS(StripeTimer, kITimerCallbackIID);
PRInt32 StripeTimer::GetFrameData(nsProgressMeterFrame* aFrame)
{
PRInt32 i, n = mFrames.Count();
for (i = 0; i < n; i++) {
FrameData* frameData = (FrameData*) mFrames.ElementAt(i);
if (frameData->mFrame == aFrame) {
return i;
}
}
return -1;
}
void StripeTimer::AddFrame(nsIPresContext* aPresContext, nsProgressMeterFrame* aFrame) {
// see if the frame is already here.
if (GetFrameData(aFrame) > -1)
return;
// if not add it.
FrameData* frameData = new FrameData(aPresContext, aFrame);
mFrames.AppendElement(frameData);
if (1 == mFrames.Count()) {
Start();
}
}
PRBool StripeTimer::RemoveFrame(nsProgressMeterFrame* aFrame) {
PRBool rv = PR_FALSE;
PRInt32 i = GetFrameData(aFrame);
if (i > -1) {
FrameData* frameData = (FrameData*)mFrames.ElementAt(i);
rv = mFrames.RemoveElementAt(i);
delete frameData;
}
if (0 == mFrames.Count()) {
Stop();
}
return rv;
}
PRInt32 StripeTimer::FrameCount() {
return mFrames.Count();
}
void StripeTimer::Notify(nsITimer *timer)
{
// XXX hack to get auto-repeating timers; restart before doing
// expensive work so that time between ticks is more even
Stop();
Start();
PRInt32 i, n = mFrames.Count();
for (i = 0; i < n; i++) {
FrameData* frameData = (FrameData*) mFrames.ElementAt(i);
frameData->mFrame->animate();
// Determine damaged area and tell view manager to redraw it
nsPoint offset;
nsRect bounds;
frameData->mFrame->GetRect(bounds);
nsIView* view;
frameData->mFrame->GetOffsetFromView(frameData->mPresContext, offset, &view);
nsIViewManager* vm;
view->GetViewManager(vm);
bounds.x = offset.x;
bounds.y = offset.y;
vm->UpdateView(view, bounds, 0);
NS_RELEASE(vm);
}
}
//
// NS_NewToolbarFrame
//
// Creates a new Toolbar frame and returns it in |aNewFrame|
//
nsresult
NS_NewProgressMeterFrame ( nsIFrame** aNewFrame )
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsProgressMeterFrame* it = new nsProgressMeterFrame;
if (nsnull == it)
return NS_ERROR_OUT_OF_MEMORY;
// it->SetFlags(aFlags);
*aNewFrame = it;
return NS_OK;
} // NS_NewProgressMeterFrame
//
// nsProgressMeterFrame cntr
//
// Init, if necessary
//
nsProgressMeterFrame :: nsProgressMeterFrame ( )
{
// if we haven't created the timer create it.
if (nsnull == gStripeAnimator) {
gStripeAnimator = new StripeTimer();
}
NS_ADDREF(gStripeAnimator);
mProgress = float(0.0);
mHorizontal = PR_TRUE;
mUndetermined = PR_FALSE;
mStripeOffset = STRIPE_WIDTH;
}
//
// nsProgressMeterFrame dstr
//
// Cleanup, if necessary
//
nsProgressMeterFrame :: ~nsProgressMeterFrame ( )
{
gStripeAnimator->RemoveFrame(this);
}
NS_IMETHODIMP
nsProgressMeterFrame::Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsLeafFrame::Init(aPresContext, aContent, aParent, aContext,
aPrevInFlow);
// get the value
nsAutoString value;
if ((NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, value)) &&
(value.Length() > 0)) {
setProgress(value);
}
// get the alignment
nsAutoString align;
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::align, align);
setAlignment(align);
// get the mode
nsAutoString mode;
mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::mode, mode);
setMode(mode);
nsCOMPtr<nsIAtom> barPseudo ( dont_AddRef(NS_NewAtom(":progressmeter-stripe")) );
nsIStyleContext* barStyle = nsnull;
aPresContext.ProbePseudoStyleContextFor(aContent, barPseudo, aContext,
PR_FALSE, &barStyle);
mBarStyle = barStyle;
return rv;
}
void
nsProgressMeterFrame::setProgress(nsAutoString progress)
{
// convert to and integer
PRInt32 error;
PRInt32 v = progress.ToInteger(&error);
// adjust to 0 and 100
if (v < 0)
v = 0;
else if (v > 100)
v = 100;
// printf("ProgressMeter value=%d\n", v);
mProgress = float(v)/float(100);
}
void
nsProgressMeterFrame::setSize(nsAutoString sizeString, int& size, PRBool& isPercent)
{
// -1 means unset
size = -1;
int length = sizeString.Length();
if (length == 0)
return;
char w[100];
sizeString.ToCString(w,100);
if (w[length-1] == '%')
isPercent = PR_TRUE;
else
isPercent = PR_FALSE;
// convert to and integer
PRInt32 error;
PRInt32 v = sizeString.ToInteger(&error);
// adjust to 0 and 100
if (isPercent) {
if (v < 0)
v = 0;
else if (v > 100)
v = 100;
}
printf("size=%d\n", v);
size = v;
}
void
nsProgressMeterFrame::setAlignment(nsAutoString progress)
{
if (progress.EqualsIgnoreCase("vertical"))
mHorizontal = PR_FALSE;
else
mHorizontal = PR_TRUE;
}
void
nsProgressMeterFrame::setMode(nsAutoString mode)
{
if (mode.EqualsIgnoreCase("undetermined"))
mUndetermined = PR_TRUE;
else
mUndetermined = PR_FALSE;
}
//
// Paint
//
// Paint our background and border like normal frames, but before we draw the
// children, draw our grippies for each toolbar.
//
NS_IMETHODIMP
nsProgressMeterFrame :: Paint ( nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)
{
const nsStyleDisplay* disp = (const nsStyleDisplay*)
mStyleContext->GetStyleData(eStyleStruct_Display);
// if we aren't visible then we are done.
if (!disp->mVisible)
return NS_OK;
// if we are visible then tell our superclass to paint
nsLeafFrame::Paint(aPresContext, aRenderingContext, aDirtyRect,
aWhichLayer);
// get our border
const nsStyleSpacing* spacing =
(const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
nsMargin border(0,0,0,0);
spacing->CalcBorderFor(this, border);
const nsStyleColor* colorStyle =
(const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
nscolor color = colorStyle->mColor;
// figure our twips convertion ratio
// float p2t;
// aPresContext.GetScaledPixelsToTwips(p2t);
// nscoord onePixel = NSIntPixelsToTwips(1, p2t);
// figure out our rectangle
nsRect rect(0,0,mRect.width, mRect.height);
// if its vertical then transform the coords to the X coordinate system
// and do our calculations there.
if (!mHorizontal)
rect = TransformYtoX(rect);
//CalcSize(aPresContext,rect.width,rect.height);
rect.x = border.left;
rect.y = border.top;
rect.width -= border.left*2;
rect.height -= border.top*2;
// paint the current progress in blue
PaintBar(aPresContext, aRenderingContext, rect, mProgress, color);
return NS_OK;
} // Paint
void
nsProgressMeterFrame :: PaintBar ( nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& rect,
float progress,
nscolor color) {
// if the bar is undetermined then use the whole progress area.
// if the bar is determined then figure out the current progress and make
// the bar only that percent of the full progress meter.
nsRect bar(rect);
if (!mUndetermined)
{
int p = (int)(bar.width*progress);
bar.width = p;
}
// fill the bar first then we will do the shading over it.
aRenderingContext.SetColor(color);
if (mHorizontal)
aRenderingContext.FillRect(bar);
else { // if we are vert then transfrom to the y cood system.
nsRect nbar = TransformXtoY(bar);
aRenderingContext.FillRect(nbar);
}
// draw the stripped barber shop if undetermined.
if (mUndetermined)
PaintBarStripped(aPresContext,aRenderingContext,bar, color);
else
PaintBarSolid(aPresContext,aRenderingContext,bar, color, 0);
}
nsRect
nsProgressMeterFrame::TransformXtoY(const nsRect& rect)
{
return nsRect(rect.y, mRect.height - (rect.x + rect.width), rect.height, rect.width);
}
nsRect
nsProgressMeterFrame::TransformYtoX(const nsRect& rect)
{
return nsRect(mRect.width - (rect.y + rect.height), rect.x, rect.height, rect.width);
}
nscolor
nsProgressMeterFrame::BrightenBy(nscolor c, PRUint8 amount)
{
PRUint8 r = NS_GET_R(c);
PRUint8 g = NS_GET_G(c);
PRUint8 b = NS_GET_B(c);
return NS_RGB(r+amount, g+amount, b+amount);
}
PRUint8
nsProgressMeterFrame::GetBrightness(nscolor c)
{
// get the biggest rgb component;
PRUint8 r = NS_GET_R(c);
PRUint8 g = NS_GET_G(c);
PRUint8 b = NS_GET_B(c);
PRUint8 biggest = r;
if (r > g && r > b)
biggest = r;
else if (g > r && g > b)
biggest = g;
else if (b > r && b > g)
biggest = b;
return biggest;
}
void
nsProgressMeterFrame::PaintBarSolid(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext,
const nsRect& rect, nscolor color, float skew)
{
// figure out a pixel size
float p2t;
aPresContext.GetScaledPixelsToTwips(&p2t);
nscoord onePixel = NSIntPixelsToTwips(1, p2t);
// how many pixel lines will fit?
int segments = (rect.height/2) / onePixel;
// get the skew in pixels;
int skewedPixels = int(skew * onePixel);
// we will draw from the top to center and from the bottom to center at the same time
// so we need 2 rects one for the top and one for the bottom
// top.
nsRect tr(rect);
tr.height= onePixel;
// bottom
nsRect br(rect);
br.height = onePixel;
br.y = rect.y + 2*segments*onePixel;
br.x = rect.x + 2*segments*skewedPixels;
// get the brightness of the color
PRUint8 brightness = GetBrightness(color);
// we need to figure out how bright we can get.
PRUint8 units = (255 - brightness)/segments;
// get a color we can set
nscolor c(color);
for (int i=0; i <= segments; i++)
{
// set the color and fill the top and bottom lines
aRenderingContext.SetColor(c);
if (mHorizontal) {
aRenderingContext.FillRect(tr);
aRenderingContext.FillRect(br);
} else {
aRenderingContext.FillRect(TransformXtoY(tr));
aRenderingContext.FillRect(TransformXtoY(br));
}
// brighten the color
c = BrightenBy(c, units);
// move one line down
tr.x += skewedPixels;
tr.y += onePixel;
// move one line up
br.y -= onePixel;
br.x -= skewedPixels;
}
}
void
nsProgressMeterFrame::PaintBarStripped(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext,
const nsRect& r, nscolor color)
{
// get stripe color from the style system
nsCOMPtr<nsIStyleContext> style (mBarStyle) ;
nscolor altColor = NS_RGB(128,128,128);
// if we got a style then get the color from it
if (style != 0)
{
const nsStyleColor* barColor = (const nsStyleColor*)style->GetStyleData(eStyleStruct_Color);
altColor = barColor->mColor;
}
float skew = STRIPE_SKEW;
float stripeWidth = float(STRIPE_WIDTH);
nsRect rect(r);
PRBool clipState;
// Clip so we don't render outside the inner rect
aRenderingContext.PushState();
if (mHorizontal)
aRenderingContext.SetClipRect(rect, nsClipCombine_kIntersect, clipState);
else
aRenderingContext.SetClipRect(TransformXtoY(rect), nsClipCombine_kIntersect, clipState);
float p2t;
aPresContext.GetScaledPixelsToTwips(&p2t);
// nscoord onePixel = NSIntPixelsToTwips(1, p2t);
int stripeWidthInTwips = (int)(stripeWidth * p2t);
int offset = int(float(r.height) * skew);
//make things a little bigger and just clip them
rect.width += offset*2;
rect.x -= (offset + int(float(mStripeOffset)*p2t));
int stripes = rect.width / (stripeWidthInTwips/2) + 2;
nsRect sr(rect.x,rect.y,stripeWidthInTwips,rect.height);
PRBool onoff = PR_FALSE;
nscolor c;
for (int i=0; i < stripes; i++)
{
if (onoff)
c = color;
else
c = altColor;
PaintBarSolid(aPresContext,aRenderingContext,sr, c, skew);
sr.x += (stripeWidthInTwips/2);
onoff = !onoff;
}
aRenderingContext.PopState(clipState);
}
void
nsProgressMeterFrame::animate()
{
mStripeOffset -= ANIMATION_INCREMENT;
// printf("animate=%d\n", mStripeOffset);
if (mStripeOffset < 0)
mStripeOffset = STRIPE_WIDTH;
}
//
// Reflow
//
// Handle moving children around.
//
NS_IMETHODIMP
nsProgressMeterFrame :: Reflow ( nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
if (eReflowReason_Incremental == aReflowState.reason) {
nsIFrame* targetFrame;
// See if it's targeted at us
aReflowState.reflowCommand->GetTarget(targetFrame);
if (this == targetFrame) {
Invalidate(&aPresContext, nsRect(0,0,mRect.width,mRect.height), PR_FALSE);
}
}
if (mUndetermined)
gStripeAnimator->AddFrame(&aPresContext, this);
else
gStripeAnimator->RemoveFrame(this);
return nsLeafFrame::Reflow ( aPresContext, aDesiredSize, aReflowState, aStatus );
} // Reflow
void
nsProgressMeterFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize)
{
CalcSize(*aPresContext,aDesiredSize.width,aDesiredSize.height);
// if the width is set use it
if (NS_INTRINSICSIZE != aReflowState.mComputedWidth)
aDesiredSize.width = aReflowState.mComputedWidth;
// if the height is set use it
if (NS_INTRINSICSIZE != aReflowState.mComputedHeight)
aDesiredSize.height = aReflowState.mComputedHeight;
}
void
nsProgressMeterFrame::CalcSize(nsIPresContext& aPresContext, int& width, int& height)
{
// make sure we convert to twips.
float p2t;
aPresContext.GetScaledPixelsToTwips(&p2t);
if (mHorizontal) {
width = (int)(100 * p2t);
height = (int)(16 * p2t);
} else {
height = (int)(100 * p2t);
width = (int)(16 * p2t);
}
}
NS_IMETHODIMP
nsProgressMeterFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint)
{
nsresult rv = nsLeafFrame::AttributeChanged(aPresContext, aChild,
aNameSpaceID, aAttribute, aHint);
if (NS_OK != rv) {
return rv;
}
// did the progress change?
if (nsHTMLAtoms::value == aAttribute) {
nsAutoString newValue;
// get attribute and set it
aChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, newValue);
setProgress(newValue);
Redraw(aPresContext);
} else if (nsXULAtoms::mode == aAttribute) {
nsAutoString newValue;
aChild->GetAttribute(kNameSpaceID_None, nsXULAtoms::mode, newValue);
setMode(newValue);
// needs to reflow so we start the timer.
if (aHint != NS_STYLE_HINT_REFLOW)
Reflow(aPresContext);
} else if (nsHTMLAtoms::align == aAttribute) {
nsAutoString newValue;
// get attribute and set it
aChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::align, newValue);
setAlignment(newValue);
if (aHint != NS_STYLE_HINT_REFLOW)
Reflow(aPresContext);
}
return NS_OK;
}
void
nsProgressMeterFrame::Reflow(nsIPresContext* aPresContext)
{
// reflow
nsCOMPtr<nsIPresShell> shell;
aPresContext->GetShell(getter_AddRefs(shell));
nsCOMPtr<nsIReflowCommand> reflowCmd;
nsresult rv = NS_NewHTMLReflowCommand(getter_AddRefs(reflowCmd), this,
nsIReflowCommand::StyleChanged);
if (NS_SUCCEEDED(rv))
shell->AppendReflowCommand(reflowCmd);
}
void
nsProgressMeterFrame::Redraw(nsIPresContext* aPresContext)
{
nsRect frameRect;
GetRect(frameRect);
nsRect rect(0, 0, frameRect.width, frameRect.height);
Invalidate(aPresContext, rect, PR_TRUE);
}
NS_IMETHODIMP
nsProgressMeterFrame::GetAdditionalStyleContext(PRInt32 aIndex,
nsIStyleContext** aStyleContext) const
{
NS_PRECONDITION(nsnull != aStyleContext, "null OUT parameter pointer");
if (aIndex < 0) {
return NS_ERROR_INVALID_ARG;
}
*aStyleContext = nsnull;
switch (aIndex) {
case NS_PROGRESS_METER_STRIPE_CONTEXT_INDEX:
*aStyleContext = mBarStyle;
NS_IF_ADDREF(*aStyleContext);
break;
default:
return NS_ERROR_INVALID_ARG;
}
return NS_OK;
}
NS_IMETHODIMP
nsProgressMeterFrame::SetAdditionalStyleContext(PRInt32 aIndex,
nsIStyleContext* aStyleContext)
{
if (aIndex < 0) {
return NS_ERROR_INVALID_ARG;
}
switch (aIndex) {
case NS_PROGRESS_METER_STRIPE_CONTEXT_INDEX:
mBarStyle = aStyleContext;
break;
}
return NS_OK;
}

View File

@@ -1,140 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
/**
Eric D Vaughan.
A simple progress meter.
Attributes:
value: A number between 0% adn 100%
align: horizontal, or vertical
mode: determined, undetermined (one shows progress other shows animated candy cane)
Style:
Bar gets its color from the color style
Alternating stripes can be set with the seudo style:
:PROGRESSMETER-STRIPE {
color: gray
}
**/
#include "nsLeafFrame.h"
#include "nsColor.h"
#include "nsCOMPtr.h"
#include "nsIStyleContext.h"
#include "nsIPresContext.h"
#include "prtypes.h"
class nsIPresContext;
class nsIStyleContext;
#define NS_PROGRESS_METER_STRIPE_CONTEXT_INDEX 1
class nsProgressMeterFrame : public nsLeafFrame
{
public:
friend nsresult NS_NewProgressMeterFrame(nsIFrame** aNewFrame);
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow);
// nsIHTMLReflow overrides
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint);
NS_IMETHOD GetAdditionalStyleContext(PRInt32 aIndex,
nsIStyleContext** aStyleContext) const;
NS_IMETHOD SetAdditionalStyleContext(PRInt32 aIndex,
nsIStyleContext* aStyleContext);
virtual void animate();
virtual void Reflow(nsIPresContext* aPresContext);
virtual void Redraw(nsIPresContext* aPresContext);
protected:
nsProgressMeterFrame();
virtual ~nsProgressMeterFrame();
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize);
virtual void CalcSize(nsIPresContext& aPresContext, int& width, int& height);
virtual void PaintBar ( nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& rect,
float progress,
nscolor color);
virtual void PaintBarStripped(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext,
const nsRect& rect, nscolor color);
virtual void PaintBarSolid(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext,
const nsRect& rect, nscolor color, float skew);
virtual nscolor BrightenBy(nscolor color, PRUint8 amount);
virtual PRUint8 GetBrightness(nscolor c);
virtual nsRect TransformXtoY(const nsRect& rect);
virtual nsRect TransformYtoX(const nsRect& rect);
// pass-by-value not allowed for a coordinator because it corresponds 1-to-1
// with an element in the UI.
nsProgressMeterFrame ( const nsProgressMeterFrame& aFrame ) ; // DO NOT IMPLEMENT
nsProgressMeterFrame& operator= ( const nsProgressMeterFrame& aFrame ) ; // DO NOT IMPLEMENT
private:
void setProgress(nsAutoString progress);
void setAlignment(nsAutoString alignment);
void setMode(nsAutoString mode);
void setSize(nsAutoString s, int& size, PRBool& isPercent);
nsCOMPtr<nsIStyleContext> mBarStyle;
float mProgress;
PRBool mHorizontal;
PRBool mUndetermined;
int mStripeOffset;
}; // class nsProgressMeterFrame

View File

@@ -1,90 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
//
// Eric Vaughan
// Netscape Communications
//
// See documentation in associated header file
//
#include "nsRepeatService.h"
#define INITAL_REPEAT_DELAY 250
#define REPEAT_DELAY 50
nsRepeatService* nsRepeatService::gInstance = nsnull;
nsRepeatService::nsRepeatService()
{
}
nsRepeatService::~nsRepeatService()
{
mCallback = nsnull;
Stop();
}
nsRepeatService*
nsRepeatService::GetInstance()
{
if (!gInstance) {
gInstance = new nsRepeatService();
gInstance->mRefCnt = 1;
}
return gInstance;
}
void nsRepeatService::Start(nsITimerCallback* aCallback)
{
mCallback = aCallback;
nsresult rv = NS_NewTimer(getter_AddRefs(mRepeatTimer));
if (NS_OK == rv) {
mRepeatTimer->Init(this, INITAL_REPEAT_DELAY);
}
}
void nsRepeatService::Stop()
{
//printf("Stopping repeat timer\n");
if (mRepeatTimer) {
mRepeatTimer->Cancel();
mRepeatTimer = nsnull;
mCallback = nsnull;
}
}
void nsRepeatService::Notify(nsITimer *timer)
{
// if the repeat delay is the initial one reset it.
if (mRepeatTimer) {
mRepeatTimer->Cancel();
NS_NewTimer(getter_AddRefs(mRepeatTimer));
mRepeatTimer->Init(this, REPEAT_DELAY);
}
mCallback->Notify(timer);
}
static NS_DEFINE_IID(kITimerCallbackIID, NS_ITIMERCALLBACK_IID);
NS_IMPL_ISUPPORTS(nsRepeatService, kITimerCallbackIID);

View File

@@ -1,244 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
//
// Eric Vaughan
// Netscape Communications
//
// See documentation in associated header file
//
#include "nsScrollbarButtonFrame.h"
#include "nsIStyleContext.h"
#include "nsIPresContext.h"
#include "nsIContent.h"
#include "nsCOMPtr.h"
#include "nsHTMLIIDs.h"
#include "nsUnitConversion.h"
#include "nsINameSpaceManager.h"
#include "nsHTMLAtoms.h"
#include "nsXULAtoms.h"
#include "nsIReflowCommand.h"
#include "nsSliderFrame.h"
#include "nsRepeatService.h"
//
// NS_NewToolbarFrame
//
// Creates a new Toolbar frame and returns it in |aNewFrame|
//
nsresult
NS_NewScrollbarButtonFrame ( nsIFrame** aNewFrame )
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsScrollbarButtonFrame* it = new nsScrollbarButtonFrame;
if (nsnull == it)
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = it;
return NS_OK;
} // NS_NewScrollBarButtonFrame
/*
nsScrollbarButtonFrame::nsScrollbarButtonFrame()
{
}*/
static NS_DEFINE_IID(kITimerCallbackIID, NS_ITIMERCALLBACK_IID);
NS_IMETHODIMP
nsScrollbarButtonFrame::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (aIID.Equals(kITimerCallbackIID)) {
*aInstancePtr = (void*)(nsITimerCallback*) this;
NS_ADDREF_THIS();
return NS_OK;
}
return nsTitledButtonFrame::QueryInterface(aIID, aInstancePtr);
}
NS_IMETHODIMP
nsScrollbarButtonFrame::HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
// XXX hack until handle release is actually called in nsframe.
if (aEvent->message == NS_MOUSE_EXIT|| aEvent->message == NS_MOUSE_RIGHT_BUTTON_UP || aEvent->message == NS_MOUSE_LEFT_BUTTON_UP)
HandleRelease(aPresContext, aEvent, aEventStatus);
return nsTitledButtonFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
}
NS_IMETHODIMP
nsScrollbarButtonFrame::HandlePress(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
nsRepeatService::GetInstance()->Start(this);
return NS_OK;
}
NS_IMETHODIMP
nsScrollbarButtonFrame::HandleRelease(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
nsRepeatService::GetInstance()->Stop();
return NS_OK;
}
void nsScrollbarButtonFrame::Notify(nsITimer *timer)
{
MouseClicked();
}
void
nsScrollbarButtonFrame::MouseClicked(nsIPresContext& aPresContext)
{
MouseClicked();
}
void
nsScrollbarButtonFrame::MouseClicked()
{
// when we are clicked either increment or decrement the slider position.
// get the scrollbar control
nsIFrame* scrollbar;
GetParentWithTag(nsXULAtoms::scrollbar, this, scrollbar);
if (scrollbar == nsnull)
return;
// get the scrollbars content node
nsCOMPtr<nsIContent> content;
scrollbar->GetContent(getter_AddRefs(content));
// get the current pos
PRInt32 curpos = nsSliderFrame::GetCurrentPosition(content);
// get the max pos
PRInt32 maxpos = nsSliderFrame::GetMaxPosition(content);
// get the increment amount
PRInt32 increment = nsSliderFrame::GetIncrement(content);
nsString value;
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, value))
{
// if our class is DecrementButton subtract the current pos by increment amount
// if our class is IncrementButton increment the current pos by the decrement amount
if (value.Equals("decrement"))
curpos -= increment;
else if (value.Equals("increment"))
curpos += increment;
// make sure the current positon is between the current and max positions
if (curpos < 0)
curpos = 0;
else if (curpos > maxpos)
curpos = maxpos;
// set the current position of the slider.
char v[100];
sprintf(v, "%d", curpos);
content->SetAttribute(kNameSpaceID_None, nsXULAtoms::curpos, v, PR_TRUE);
}
}
nsresult
nsScrollbarButtonFrame::GetChildWithTag(nsIAtom* atom, nsIFrame* start, nsIFrame*& result)
{
// recursively search our children
nsIFrame* childFrame;
start->FirstChild(nsnull, &childFrame);
while (nsnull != childFrame)
{
// get the content node
nsCOMPtr<nsIContent> child;
childFrame->GetContent(getter_AddRefs(child));
if (child) {
// see if it is the child
nsIAtom* tag = nsnull;
child->GetTag(tag);
if (tag == atom)
{
result = childFrame;
return NS_OK;
}
}
// recursive search the child
GetChildWithTag(atom, childFrame, result);
if (result != nsnull)
return NS_OK;
nsresult rv = childFrame->GetNextSibling(&childFrame);
NS_ASSERTION(rv == NS_OK,"failed to get next child");
}
result = nsnull;
return NS_OK;
}
nsresult
nsScrollbarButtonFrame::GetParentWithTag(nsIAtom* toFind, nsIFrame* start, nsIFrame*& result)
{
while(nsnull != start)
{
start->GetParent(&start);
if (start) {
// get the content node
nsCOMPtr<nsIContent> child;
start->GetContent(getter_AddRefs(child));
nsIAtom* atom;
if (child && child->GetTag(atom) == NS_OK && atom == toFind) {
result = start;
return NS_OK;
}
}
}
result = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsScrollbarButtonFrame::Destroy(nsIPresContext& aPresContext)
{
// Ensure our repeat service isn't going... it's possible that a scrollbar can disappear out
// from under you while you're in the process of scrolling.
nsRepeatService::GetInstance()->Stop();
return nsTitledButtonFrame::Destroy(aPresContext);
}

View File

@@ -1,86 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
/**
Eric D Vaughan
This class lays out its children either vertically or horizontally
**/
#ifndef nsScrollbarButtonFrame_h___
#define nsScrollbarButtonFrame_h___
#include "nsTitledButtonFrame.h"
#include "nsITimerCallback.h"
class nsSliderFrame;
class nsScrollbarButtonFrame : public nsTitledButtonFrame,
public nsITimerCallback
{
public:
// Overrides
NS_IMETHOD Destroy(nsIPresContext& aPresContext);
friend nsresult NS_NewScrollBarButtonFrame(nsIFrame** aNewFrame);
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
static nsresult GetChildWithTag(nsIAtom* atom, nsIFrame* start, nsIFrame*& result);
static nsresult GetParentWithTag(nsIAtom* atom, nsIFrame* start, nsIFrame*& result);
NS_IMETHOD HandlePress(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD HandleMultiplePress(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus) { return NS_OK; }
NS_IMETHOD HandleDrag(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus) { return NS_OK; }
NS_IMETHOD HandleRelease(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus);
virtual void Notify(nsITimer *timer);
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void) { return NS_OK; }
NS_IMETHOD_(nsrefcnt) Release(void) { return NS_OK; }
protected:
virtual void MouseClicked(nsIPresContext& aPresContext);
virtual void MouseClicked();
}; // class nsTabFrame
#endif

View File

@@ -1,390 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
//
// Eric Vaughan
// Netscape Communications
//
// See documentation in associated header file
//
#include "nsScrollbarFrame.h"
#include "nsScrollbarButtonFrame.h"
#include "nsXULAtoms.h"
#include "nsHTMLAtoms.h"
#include "nsISupportsArray.h"
#include "nsXULAtoms.h"
#include "nsHTMLAtoms.h"
#include "nsINameSpaceManager.h"
#include "nsIXMLContent.h"
#include "nsIDOMDocument.h"
#include "nsIDocument.h"
#include "nsIDOMElement.h"
#include "nsXMLElement.h"
#include "nsIStyledContent.h"
#include "nsGenericElement.h"
#include "nsIStyleRule.h"
#include "nsHTMLValue.h"
#include "nsIAnonymousContent.h"
#include "nsIView.h"
static NS_DEFINE_IID(kIAnonymousContentCreatorIID, NS_IANONYMOUS_CONTENT_CREATOR_IID);
static NS_DEFINE_IID(kIStyledContentIID, NS_ISTYLEDCONTENT_IID);
static NS_DEFINE_IID(kIAnonymousContentIID, NS_IANONYMOUS_CONTENT_IID);
class AnonymousElement : public nsXMLElement, nsIStyledContent, nsIAnonymousContent
{
public:
AnonymousElement(nsIAtom *aTag):nsXMLElement(aTag) {}
// nsIStyledContent
NS_IMETHOD GetID(nsIAtom*& aResult) const;
NS_IMETHOD GetClasses(nsVoidArray& aArray) const;
NS_IMETHOD HasClass(nsIAtom* aClass) const;
NS_IMETHOD GetContentStyleRules(nsISupportsArray* aRules);
NS_IMETHOD GetInlineStyleRules(nsISupportsArray* aRules);
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
PRInt32& aHint) const;
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
NS_IMPL_ICONTENT_USING_GENERIC(mInner)
// NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(mInner)
};
NS_IMETHODIMP
AnonymousElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const {
return this->nsXMLElement::SizeOf(aSizer, aResult);
}
/*
NS_IMETHODIMP
AnonymousElement::GetTag(nsIAtom*& aResult) const
{
return mInner.GetTag(aResult);
}
NS_IMETHODIMP
AnonymousElement::List(FILE* out, PRInt32 aIndent) const
{
NS_PRECONDITION(nsnull != mInner.mDocument, "bad content");
PRInt32 indx;
for (indx = aIndent; --indx >= 0; ) fputs(" ", out);
fprintf(out, "Comment refcount=%d<", mRefCnt);
nsAutoString tmp;
mInner.ToCString(tmp, 0, mInner.mText.GetLength());
fputs(tmp, out);
fputs(">\n", out);
return mInner.List(out, aIndent);
}
*/
NS_IMETHODIMP
AnonymousElement::HandleDOMEvent(nsIPresContext& aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
PRUint32 aFlags,
nsEventStatus& aEventStatus)
{
/*
// if our parent is not anonymous then we don't want to bubble the event
// so lets set our parent in nsnull to prevent it. Then we will set it
// back.
nsIContent* parent = nsnull;
GetParent(parent);
nsCOMPtr<nsIAnonymousContent> anonymousParent(do_QueryInterface(parent));
if (!anonymousParent)
SetParent(nsnull);
*/
nsresult rv = mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
aFlags, aEventStatus);
/*
if (!anonymousParent)
SetParent(parent);
*/
return rv;
}
// nsIStyledContent Implementation
NS_IMETHODIMP
AnonymousElement::GetID(nsIAtom*& aResult) const
{
/*
nsAutoString value;
GetAttribute(kNameSpaceID_None, kIdAtom, value);
aResult = NS_NewAtom(value); // The NewAtom call does the AddRef.
*/
aResult = nsnull;
return NS_OK;
}
NS_IMETHODIMP
AnonymousElement::GetClasses(nsVoidArray& aArray) const
{
return NS_OK;
}
NS_IMETHODIMP
AnonymousElement::HasClass(nsIAtom* aClass) const
{
return NS_COMFALSE;
}
NS_IMETHODIMP
AnonymousElement::GetContentStyleRules(nsISupportsArray* aRules)
{
return NS_OK;
}
NS_IMETHODIMP
AnonymousElement::GetInlineStyleRules(nsISupportsArray* aRules)
{
// we don't currently support the style attribute
return NS_OK;
}
NS_IMETHODIMP
AnonymousElement::GetMappedAttributeImpact(const nsIAtom* aAttribute,
PRInt32& aHint) const
{
aHint = NS_STYLE_HINT_CONTENT; // we never map attribtes to style
return NS_OK;
}
NS_IMETHODIMP
AnonymousElement::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (aIID.Equals(kIStyledContentIID)) {
nsIStyledContent* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
} else if (aIID.Equals(kIAnonymousContentIID)) {
nsIAnonymousContent* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
return nsXMLElement::QueryInterface(aIID, aInstancePtr);
}
NS_IMPL_ADDREF_INHERITED(AnonymousElement, nsXMLElement)
NS_IMPL_RELEASE_INHERITED(AnonymousElement, nsXMLElement)
nsresult NS_CreateAnonymousNode(nsIContent* aParent, nsIAtom* aTag, PRInt32 aNameSpaceId, nsCOMPtr<nsIContent>& aNewNode)
{
// create the xml element
nsCOMPtr<nsIXMLContent> content;
//NS_NewXMLElement(getter_AddRefs(content), aTag);
content = new AnonymousElement(aTag);
content->SetNameSpaceID(aNameSpaceId);
aNewNode = content;
/*
nsCOMPtr<nsIDocument> document;
aParent->GetDocument(*getter_AddRefs(document));
nsCOMPtr<nsIDOMDocument> domDocument(do_QueryInterface(document));
nsCOMPtr<nsIDOMElement> element;
nsString name;
aTag->ToString(name);
domDocument->CreateElement(name, getter_AddRefs(element));
aNewNode = do_QueryInterface(element);
*/
return NS_OK;
}
//
// NS_NewToolbarFrame
//
// Creates a new Toolbar frame and returns it in |aNewFrame|
//
nsresult
NS_NewScrollbarFrame ( nsIFrame** aNewFrame )
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsScrollbarFrame* it = new nsScrollbarFrame;
if (nsnull == it)
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = it;
return NS_OK;
} // NS_NewScrollbarFrame
/**
* Anonymous interface
*/
NS_IMETHODIMP
nsScrollbarFrame::CreateAnonymousContent(nsISupportsArray& aAnonymousChildren)
{
// if not content the create some anonymous content
PRInt32 count = 0;
mContent->ChildCount(count);
if (count == 0) {
nsCOMPtr<nsIContent> content;
NS_CreateAnonymousNode(mContent, nsXULAtoms::scrollbarbutton, nsXULAtoms::nameSpaceID, content);
content->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, "decrement", PR_FALSE);
aAnonymousChildren.AppendElement(content);
NS_CreateAnonymousNode(mContent, nsXULAtoms::slider, nsXULAtoms::nameSpaceID, content);
content->SetAttribute(kNameSpaceID_None, nsXULAtoms::flex, "1", PR_FALSE);
aAnonymousChildren.AppendElement(content);
NS_CreateAnonymousNode(mContent, nsXULAtoms::scrollbarbutton, nsXULAtoms::nameSpaceID, content);
content->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, "increment", PR_FALSE);
aAnonymousChildren.AppendElement(content);
}
return NS_OK;
}
NS_IMETHODIMP
nsScrollbarFrame::Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
CreateViewForFrame(aPresContext,this,aContext,PR_TRUE);
nsIView* view;
GetView(&aPresContext, &view);
view->SetContentTransparency(PR_TRUE);
return rv;
}
NS_IMETHODIMP
nsScrollbarFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint)
{
nsresult rv = nsBoxFrame::AttributeChanged(aPresContext, aChild,
aNameSpaceID, aAttribute, aHint);
// if the current position changes
if ( aAttribute == nsXULAtoms::curpos ||
aAttribute == nsXULAtoms::maxpos ||
aAttribute == nsXULAtoms::pageincrement ||
aAttribute == nsXULAtoms::increment) {
// tell the slider its attribute changed so it can
// update itself
nsIFrame* slider;
nsScrollbarButtonFrame::GetChildWithTag(nsXULAtoms::slider, this, slider);
if (slider)
slider->AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aHint);
}
return rv;
}
NS_IMETHODIMP
nsScrollbarFrame::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
*aInstancePtr = NULL;
if (aIID.Equals(kIAnonymousContentCreatorIID)) {
*aInstancePtr = (void*)(nsIAnonymousContentCreator*) this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIStyledContentIID)) {
*aInstancePtr = (void*)(nsIStyledContent*) this;
NS_ADDREF_THIS();
return NS_OK;
}
return nsBoxFrame::QueryInterface(aIID, aInstancePtr);
}
NS_IMETHODIMP
nsScrollbarFrame::HandlePress(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
return NS_OK;
}
NS_IMETHODIMP
nsScrollbarFrame::HandleMultiplePress(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
return NS_OK;
}
NS_IMETHODIMP
nsScrollbarFrame::HandleDrag(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
return NS_OK;
}
NS_IMETHODIMP
nsScrollbarFrame::HandleRelease(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
return NS_OK;
}

View File

@@ -1,85 +0,0 @@
/* -*- 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.
*/
//
// nsScrollbarFrame
//
#ifndef nsScrollbarFrame_h__
#define nsScrollbarFrame_h__
#include "nsBoxFrame.h"
#include "nsIAnonymousContentCreator.h"
class nsISupportsArray;
nsresult NS_NewScrollbarFrame(nsIFrame** aResult) ;
class nsScrollbarFrame : public nsBoxFrame,
public nsIAnonymousContentCreator
{
public:
nsScrollbarFrame() {}
#ifdef DEBUG
NS_IMETHOD GetFrameName(nsString& aResult) const {
return MakeFrameName("ScrollbarFrame", aResult);
}
#endif
// nsIFrame overrides
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint);
// nsIAnonymousConentCreator
NS_IMETHOD CreateAnonymousContent(nsISupportsArray& aAnonymousItems);
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; }
NS_IMETHOD HandlePress(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD HandleMultiplePress(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD HandleDrag(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD HandleRelease(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow);
}; // class nsScrollbarFrame
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,234 +0,0 @@
/* -*- 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.
*/
//
// nsSliderFrame
//
#ifndef nsSliderFrame_h__
#define nsSliderFrame_h__
#include "nsHTMLContainerFrame.h"
#include "prtypes.h"
#include "nsIAtom.h"
#include "nsCOMPtr.h"
#include "nsIDOMMouseListener.h"
#include "nsIAnonymousContentCreator.h"
#include "nsITimerCallback.h"
class nsString;
class nsIScrollbarListener;
class nsISupportsArray;
class nsITimer;
#define INITAL_REPEAT_DELAY 500
#define REPEAT_DELAY 50
nsresult NS_NewSliderFrame(nsIFrame** aResult) ;
class nsSliderFrame : public nsHTMLContainerFrame,
nsIDOMMouseListener,
nsIAnonymousContentCreator,
nsITimerCallback
{
public:
nsSliderFrame();
virtual ~nsSliderFrame();
#ifdef DEBUG
NS_IMETHOD GetFrameName(nsString& aResult) const {
return MakeFrameName("SliderFrame", aResult);
}
#endif
// nsIFrame overrides
NS_IMETHOD Destroy(nsIPresContext& aPresContext);
NS_IMETHOD Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint);
virtual nsresult CurrentPositionChanged(nsIPresContext* aPresContext);
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* asPrevInFlow);
NS_IMETHOD CreateAnonymousContent(nsISupportsArray& aAnonymousItems);
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD AppendFrames(nsIPresContext& aPresContext,
nsIPresShell& aPresShell,
nsIAtom* aListName,
nsIFrame* aFrameList);
NS_IMETHOD InsertFrames(nsIPresContext& aPresContext,
nsIPresShell& aPresShell,
nsIAtom* aListName,
nsIFrame* aPrevFrame,
nsIFrame* aFrameList);
NS_IMETHOD RemoveFrame(nsIPresContext& aPresContext,
nsIPresShell& aPresShell,
nsIAtom* aListName,
nsIFrame* aOldFrame);
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext,
const nsPoint& aPoint, nsIFrame** aFrame);
NS_IMETHOD SetInitialChildList(nsIPresContext& aPresContext,
nsIAtom* aListName,
nsIFrame* aChildList);
/**
* Processes a mouse down event
* @param aMouseEvent @see nsIDOMEvent.h
* @returns whether the event was consumed or ignored. @see nsresult
*/
virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent);
/**
* Processes a mouse up event
* @param aMouseEvent @see nsIDOMEvent.h
* @returns whether the event was consumed or ignored. @see nsresult
*/
virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent);
/**
* Processes a mouse click event
* @param aMouseEvent @see nsIDOMEvent.h
* @returns whether the event was consumed or ignored. @see nsresult
*
*/
virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent) { return NS_OK; }
/**
* Processes a mouse click event
* @param aMouseEvent @see nsIDOMEvent.h
* @returns whether the event was consumed or ignored. @see nsresult
*
*/
virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent) { return NS_OK; }
/**
* Processes a mouse enter event
* @param aMouseEvent @see nsIDOMEvent.h
* @returns whether the event was consumed or ignored. @see nsresult
*/
virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent) { return NS_OK; }
/**
* Processes a mouse leave event
* @param aMouseEvent @see nsIDOMEvent.h
* @returns whether the event was consumed or ignored. @see nsresult
*/
virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent) { return NS_OK; }
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }
static PRInt32 GetCurrentPosition(nsIContent* content);
static PRInt32 GetMaxPosition(nsIContent* content);
static PRInt32 GetIncrement(nsIContent* content);
static PRInt32 GetPageIncrement(nsIContent* content);
static PRInt32 GetIntegerAttribute(nsIContent* content, nsIAtom* atom, PRInt32 defaultValue);
static PRInt32 IsHorizontal(nsIContent* content);
void SetScrollbarListener(nsIScrollbarListener* aListener);
NS_IMETHOD HandlePress(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD HandleMultiplePress(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus) { return NS_OK; }
NS_IMETHOD HandleDrag(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus) { return NS_OK; }
NS_IMETHOD HandleRelease(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus);
virtual void Notify(nsITimer *timer);
protected:
virtual nsresult ReflowThumb(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus,
nsIFrame* thumbFrame,
nsSize available,
nsSize computed);
virtual PRIntn GetSkipSides() const { return 0; }
private:
nsIContent* GetScrollBar();
void PageUpDown(nsIFrame* aThumbFrame, nscoord change);
void SetCurrentPosition(nsIContent* scrollbar, nsIFrame* aThumbFrame, nscoord pos);
NS_IMETHOD DragThumb(nsIPresContext* aPresContext, PRBool aGrabMouseEvents);
void AddListener();
void RemoveListener();
PRBool isDraggingThumb(nsIPresContext* aPresContext);
float mRatio;
nscoord mDragStartPx;
nscoord mThumbStart;
PRInt32 mCurPos;
nsIScrollbarListener* mScrollbarListener;
// XXX Hack
nsIPresContext* mPresContext; // weak reference
static nscoord gChange;
}; // class nsSliderFrame
#endif

View File

@@ -1,111 +0,0 @@
/* -*- 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 "nsSpinnerFrame.h"
#include "nsIContent.h"
#include "prtypes.h"
#include "nsIAtom.h"
#include "nsIPresContext.h"
#include "nsIStyleContext.h"
#include "nsCSSRendering.h"
#include "nsINameSpaceManager.h"
//
// NS_NewSpinnerFrame
//
// Wrapper for creating a new spinner
//
nsresult
NS_NewSpinnerFrame(nsIFrame** aNewFrame)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsSpinnerFrame* it = new nsSpinnerFrame;
if ( !it )
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = it;
return NS_OK;
}
//
// nsSpinnerFrame cntr
//
nsSpinnerFrame::nsSpinnerFrame()
{
} // cntr
//
// Paint
//
// Overidden to handle ???
//
NS_METHOD
nsSpinnerFrame::Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)
{
return nsLeafFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
}
//
// GetDesiredSize
//
// For now, be as big as CSS wants us to be, or some small default size.
//
void
nsSpinnerFrame :: GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredLayoutSize)
{
const int CSS_NOTSET = -1;
nsSize styleSize;
if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedWidth) {
styleSize.width = aReflowState.mComputedWidth;
}
else {
styleSize.width = CSS_NOTSET;
}
if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedHeight) {
styleSize.height = aReflowState.mComputedHeight;
}
else {
styleSize.height = CSS_NOTSET;
}
// subclasses should always override this method, but if not and no css, make it small
aDesiredLayoutSize.width = (styleSize.width > CSS_NOTSET) ? styleSize.width : 200;
aDesiredLayoutSize.height = (styleSize.height > CSS_NOTSET) ? styleSize.height : 200;
aDesiredLayoutSize.ascent = aDesiredLayoutSize.height;
aDesiredLayoutSize.descent = 0;
if (aDesiredLayoutSize.maxElementSize) {
aDesiredLayoutSize.maxElementSize->width = aDesiredLayoutSize.width;
aDesiredLayoutSize.maxElementSize->height = aDesiredLayoutSize.height;
}
} // GetDesiredSize

View File

@@ -1,63 +0,0 @@
/* -*- 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.
*/
//
// nsSpinnerFrame
//
#ifndef nsSpinnerFrame_h__
#define nsSpinnerFrame_h__
#include "nsLeafFrame.h"
#include "prtypes.h"
#include "nsIAtom.h"
#include "nsCOMPtr.h"
class nsString;
nsresult NS_NewSpinnerFrame(nsIFrame** aResult) ;
class nsSpinnerFrame : public nsLeafFrame
{
public:
nsSpinnerFrame();
#ifdef DEBUG
NS_IMETHOD GetFrameName(nsString& aResult) const {
return MakeFrameName("SpinnerFrame", aResult);
}
#endif
// nsIFrame overrides
NS_IMETHOD Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
protected:
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize) ;
}; // class nsSpinnerFrame
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,103 +0,0 @@
/* -*- 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.
*/
//
// nsSplitterFrame
//
#ifndef nsSplitterFrame_h__
#define nsSplitterFrame_h__
#include "nsBoxFrame.h"
#include "nsIAnonymousContentCreator.h"
class nsISupportsArray;
class nsSplitterFrameImpl;
nsresult NS_NewSplitterFrame(nsIFrame** aResult) ;
class nsSplitterFrame : public nsBoxFrame, public nsIAnonymousContentCreator
{
public:
nsSplitterFrame();
~nsSplitterFrame();
#ifdef DEBUG
NS_IMETHOD GetFrameName(nsString& aResult) const {
return MakeFrameName("SplitterFrame", aResult);
}
#endif
// nsIFrame overrides
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint);
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow);
NS_IMETHOD GetCursor(nsIPresContext& aPresContext,
nsPoint& aPoint,
PRInt32& aCursor);
// nsIAnonymousContentCreator
NS_IMETHOD CreateAnonymousContent(nsISupportsArray& aAnonymousItems);
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void) { return NS_OK; }
NS_IMETHOD_(nsrefcnt) Release(void) { return NS_OK; }
NS_IMETHOD HandlePress(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD HandleMultiplePress(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD HandleDrag(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD HandleRelease(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext, const nsPoint& aPoint, nsIFrame** aFrame);
private:
friend class nsSplitterFrameImpl;
nsSplitterFrameImpl* mImpl;
// XXX Hack
nsIPresContext* mPresContext; // weak reference
}; // class nsSplitterFrame
#endif

View File

@@ -1,256 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#include "nsStdColorPicker.h"
#include "nsColor.h"
#include "nsCRT.h"
#include "nsXULAtoms.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"
#include "prtypes.h"
#include "nsIAtom.h"
#include "nsIPresContext.h"
#include "nsIStyleContext.h"
#include "nsCSSRendering.h"
#include "nsINameSpaceManager.h"
static char *NosePalette[] = {
"#00FF00","#00ED00","#00DB00","#00C900","#00B700","#00A500","#009300","#008100","#006F00","#005D00",
"#FFFF00","#EDED00","#DBDB00","#C9C900","#B7B700","#A5A500","#939300","#818100","#6F6F00","#5D5D00",
"#FFFF00","#F5ED00","#EBDB00","#E1C900","#D7B700","#CDA500","#C39300","#B98100","#AF6F00","#A55D00"
};
static char* StandardPalette[] = {
"#FFFFFF","#FFCCCC","#FFCC99","#FFFF99","#FFFFCC","#99FF99","#99FFFF","#CCFFFF","#CCCCFF","#FFCCFF",
"#CCCCCC","#FF6666","#FFCC33","#FFFF66","#FFFF99","#66FF99","#33FFFF","#66FFFF","#9999FF","#FF99FF",
"#C0C0C0","#FF0000","#FF9900","#FFCC66","#FFFF00","#33FF33","#66CCCC","#33CCFF","#6666CC","#CC66CC",
"#999999","#CC0000","#FF6600","#FFCC33","#FFCC00","#33CC00","#00CCCC","#3366FF","#6633FF","#CC33CC",
"#666666","#990000","#CC6600","#CC9933","#999900","#009900","#339999","#3333FF","#6600CC","#993399",
"#333333","#660000","#993300","#996633","#666600","#006600","#336666","#000099","#333399","#663366",
"#000000","#330000","#663300","#663333","#333300","#003300","#003333","#000066","#330099","#330033"
};
static char *WebPalette[] = {
"#FFFFFF", "#FFFFCC", "#FFFF99", "#FFFF66", "#FFFF33", "#FFFF00", "#FFCCFF", "#FFCCCC",
"#FFCC99", "#FFCC66", "#FFCC33", "#FFCC00", "#FF99FF", "#FF99CC", "#FF9999", "#FF9966",
"#FF9933", "#FF9900", "#FF66FF", "#FF66CC", "#FF6699", "#FF6666", "#FF6633", "#FF6600",
"#FF33FF", "#FF33CC", "#FF3399", "#FF3366", "#FF3333", "#FF3300", "#FF00FF", "#FF00CC",
"#FF0099", "#FF0066", "#FF0033", "#FF0000", "#CCFFFF", "#CCFFCC", "#CCFF99", "#CCFF66",
"#CCFF33", "#CCFF00", "#CCCCFF", "#CCCCCC", "#CCCC99", "#CCCC66", "#CCCC33", "#CCCC00",
"#CC99FF", "#CC99CC", "#CC9999", "#CC9966", "#CC9933", "#CC9900", "#CC66FF", "#CC66CC",
"#CC6699", "#CC6666", "#CC6633", "#CC6600", "#CC33FF", "#CC33CC", "#CC3399", "#CC3366",
"#CC3333", "#CC3300", "#CC00FF", "#CC00CC", "#CC0099", "#CC0066", "#CC0033", "#CC0000",
"#99FFFF", "#99FFCC", "#99FF99", "#99FF66", "#99FF33", "#99FF00", "#99CCFF", "#99CCCC",
"#99CC99", "#99CC66", "#99CC33", "#99CC00", "#9999FF", "#9999CC", "#999999", "#999966",
"#999933", "#999900", "#9966FF", "#9966CC", "#996699", "#996666", "#996633", "#996600",
"#9933FF", "#9933CC", "#993399", "#993366", "#993333", "#993300", "#9900FF", "#9900CC",
"#990099", "#990066", "#990033", "#990000", "#66FFFF", "#66FFCC", "#66FF99", "#66FF66",
"#66FF33", "#66FF00", "#66CCFF", "#66CCCC", "#66CC99", "#66CC66", "#66CC33", "#66CC00",
"#6699FF", "#6699CC", "#669999", "#669966", "#669933", "#669900", "#6666FF", "#6666CC",
"#666699", "#666666", "#666633", "#666600", "#6633FF", "#6633CC", "#663399", "#663366",
"#663333", "#663300", "#6600FF", "#6600CC", "#660099", "#660066", "#660033", "#660000",
"#33FFFF", "#33FFCC", "#33FF99", "#33FF66", "#33FF33", "#33FF00", "#33CCFF", "#33CCCC",
"#33CC99", "#33CC66", "#33CC33", "#33CC00", "#3399FF", "#3399CC", "#339999", "#339966",
"#339933", "#339900", "#3366FF", "#3366CC", "#336699", "#336666", "#336633", "#336600",
"#3333FF", "#3333CC", "#333399", "#333366", "#333333", "#333300", "#3300FF", "#3300CC",
"#330099", "#330066", "#330033", "#330000", "#00FFFF", "#00FFCC", "#00FF99", "#00FF66",
"#00FF33", "#00FF00", "#00CCFF", "#00CCCC", "#00CC99", "#00CC66", "#00CC33", "#00CC00",
"#0099FF", "#0099CC", "#009999", "#009966", "#009933", "#009900", "#0066FF", "#0066CC",
"#006699", "#006666", "#006633", "#006600", "#0033FF", "#0033CC", "#003399", "#003366",
"#003333", "#003300", "#0000FF", "#0000CC", "#000099", "#000066", "#000033", "#000000"
};
static char *GrayPalette[] = {
"#000000", "#010101", "#020202", "#030303", "#040404", "#050505", "#060606", "#070707",
"#080808", "#090909", "#0A0A0A", "#0B0B0B", "#0C0C0C", "#0D0D0D", "#0E0E0E", "#0F0F0F",
"#101010", "#111111", "#121212", "#131313", "#141414", "#151515", "#161616", "#171717",
"#181818", "#191919", "#1A1A1A", "#1B1B1B", "#1C1C1C", "#1D1D1D", "#1E1E1E", "#1F1F1F",
"#202020", "#212121", "#222222", "#232323", "#242424", "#252525", "#262626", "#272727",
"#282828", "#292929", "#2A2A2A", "#2B2B2B", "#2C2C2C", "#2D2D2D", "#2E2E2E", "#2F2F2F",
"#303030", "#313131", "#323232", "#333333", "#343434", "#353535", "#363636", "#373737",
"#383838", "#393939", "#3A3A3A", "#3B3B3B", "#3C3C3C", "#3D3D3D", "#3E3E3E", "#3F3F3F",
"#404040", "#414141", "#424242", "#434343", "#444444", "#454545", "#464646", "#474747",
"#484848", "#494949", "#4A4A4A", "#4B4B4B", "#4C4C4C", "#4D4D4D", "#4E3E3E", "#4F4F4F",
"#505050", "#515151", "#525252", "#534343", "#545454", "#555555", "#565656", "#575757",
"#585858", "#595959", "#5A5A5A", "#5B5B5B", "#5C5C5C", "#5D5D5D", "#5E5E5E", "#5F5F5F",
"#606060", "#616161", "#626262", "#636363", "#646464", "#656565", "#666666", "#676767",
"#686868", "#696969", "#6A6A6A", "#6B6B6B", "#6C6C6C", "#6D6D6D", "#6E6E6E", "#6F6F6F",
"#707070", "#717171", "#727272", "#737373", "#747474", "#757575", "#767676", "#777777",
"#787878", "#797979", "#7A7A7A", "#7B7B7B", "#7C7C7C", "#7D7D7D", "#7E7E7E", "#7F7F7F",
"#808080", "#818181", "#828282", "#838383", "#848484", "#858585", "#868686", "#878787",
"#888888", "#898989", "#8A8A8A", "#8B8B8B", "#8C8C8C", "#8D8D8D", "#8E8E8E", "#8F8F8F",
"#909090", "#919191", "#929292", "#939393", "#949494", "#959595", "#969696", "#979797",
"#989898", "#999999", "#9A9A9A", "#9B9B9B", "#9C9C9C", "#9D9D9D", "#9E9E9E", "#9F9F9F",
"#A0A0A0", "#A1A1A1", "#A2A2A2", "#A3A3A3", "#A4A4A4", "#A5A5A5", "#A6A6A6", "#A7A7A7",
"#A8A8A8", "#A9A9A9", "#AAAAAA", "#ABABAB", "#ACACAC", "#ADADAD", "#AEAEAE", "#AFAFAF",
"#B0B0B0", "#B1B1B1", "#B2B2B2", "#B3B3B3", "#B4B4B4", "#B5B5B5", "#B6B6B6", "#B7B7B7",
"#B8B8B8", "#B9B9B9", "#BABABA", "#BBBBBB", "#BCBCBC", "#BDBDBD", "#BEBEBE", "#BFBFBF",
"#C0C0C0", "#C1C1C1", "#C2C2C2", "#C3C3C3", "#C4C4C4", "#C5C5C5", "#C6C6C6", "#C7C7C7",
"#C8C8C8", "#C9C9C9", "#CACACA", "#CBCBCB", "#CCCCCC", "#CDCDCD", "#CECECE", "#CFCFCF",
"#D0D0D0", "#D1D1D1", "#D2D2D2", "#D3D3D3", "#D4D4D4", "#D5D5D5", "#D6D6D6", "#D7D7D7",
"#D8D8D8", "#D9D9D9", "#DADADA", "#DBDBDB", "#DCDCDC", "#DDDDDD", "#DEDEDE", "#DFDFDF",
"#E0E0E0", "#E1E1E1", "#E2E2E2", "#E3E3E3", "#E4E4E4", "#E5E5E5", "#E6E6E6", "#E7E7E7",
"#E8E8E8", "#E9E9E9", "#EAEAEA", "#EBEBEB", "#ECECEC", "#EDEDED", "#EEEEEE", "#EFEFEF",
"#F0F0F0", "#F1F1F1", "#F2F2F2", "#F3F3F3", "#F4F4F4", "#F5F5F5", "#F6F6F6", "#F7F7F7",
"#F8F8F8", "#F9F9F9", "#FAFAFA", "#FBFBFB", "#FCFCFC", "#FDFDFD", "#FEFEFE", "#FFFFFF"
};
NS_IMPL_ISUPPORTS1(nsStdColorPicker, nsIColorPicker)
nsStdColorPicker::nsStdColorPicker()
{
mColors = 0;
mNumCols = 0;
mNumRows = 0;
mFrameWidth = 0;
mFrameHeight = 0;
mBlockWidth = 20;
mBlockHeight = 20;
}
nsStdColorPicker::~nsStdColorPicker()
{
}
NS_IMETHODIMP nsStdColorPicker::Init(nsIContent *aContent)
{
nsAutoString palette;
aContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::palettename, palette);
if (palette.EqualsIgnoreCase("web"))
{
printf("web picked\n");
mPalette = WebPalette;
mNumCols = 12;
mColors = sizeof(WebPalette) / sizeof(char *);
}
else if (palette.EqualsIgnoreCase("nose"))
{
printf("nose picked\n");
mPalette = NosePalette;
mNumCols = 10;
mColors = sizeof(NosePalette) / sizeof(char *);
}
else if (palette.EqualsIgnoreCase("gray") || palette.EqualsIgnoreCase("grey"))
{
printf("gray picked\n");
mPalette = GrayPalette;
mNumCols = 10;
mColors = sizeof(GrayPalette) / sizeof(char *);
}
else
{
printf("standard picked\n");
mPalette = StandardPalette;
mNumCols = 10;
mColors = sizeof(StandardPalette) / sizeof(char *);
}
mNumRows = NSToIntCeil(nscoord(mColors/mNumCols)) - 1;
return NS_OK;
}
NS_IMETHODIMP nsStdColorPicker::Paint(nsIPresContext * aPresContext, nsIRenderingContext * aRenderingContext)
{
int i = 0;
int row = 0;
int col = 0;
nscolor color = 0;
float p2t;
PRInt32 width, height;
aPresContext->GetScaledPixelsToTwips(&p2t);
width = NSToIntRound(mBlockWidth * p2t);
height = NSToIntRound(mBlockHeight * p2t);
// aRenderingContext->SetColor(0);
// aRenderingContext->FillRect(0, 0, (mNumCols)*width, mNumRows*height);
for (i=0;i<mColors;i++)
{
NS_LooseHexToRGB(mPalette[i], &color);
aRenderingContext->SetColor(color);
aRenderingContext->FillRect(col*width, row*height, width, height);
if (col+1 == mNumCols)
{
col = 0;
row++;
}
else
col++;
}
return NS_OK;
}
NS_IMETHODIMP nsStdColorPicker::GetColor(PRInt32 aX, PRInt32 aY, char **aColor)
{
int cur_col = aX / mBlockWidth;
int cur_row = aY / mBlockHeight;
int f = mNumCols * cur_row + cur_col;
if (f >= mColors)
{
return NS_ERROR_FAILURE;
}
*aColor = nsCRT::strdup(mPalette[f]);
return NS_OK;
}
NS_IMETHODIMP nsStdColorPicker::SetSize(PRInt32 aWidth, PRInt32 aHeight)
{
mFrameWidth = aWidth;
mFrameHeight = aHeight;
if (aWidth != -1)
mBlockWidth = NSToIntRound(nscoord(aWidth / mNumCols));
if (aWidth != -1)
mBlockHeight = NSToIntRound(nscoord(aHeight / mNumRows));
mFrameWidth = NSToIntRound(nscoord((mNumCols) * mBlockWidth));
mFrameHeight = NSToIntRound(nscoord((mNumRows) * mBlockHeight));
return NS_OK;
}
NS_IMETHODIMP nsStdColorPicker::GetSize(PRInt32 *aWidth, PRInt32 *aHeight)
{
*aWidth = mFrameWidth;
*aHeight = mFrameHeight;
return NS_OK;
}

View File

@@ -1,55 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#ifndef __nsStdColorPicker_h__
#define __nsStdColorPicker_h__
#include "nsISupports.h"
#include "nsrootidl.h"
#include "nsIPresContext.h"
#include "nsIRenderingContext.h"
#include "nsIColorPicker.h"
class nsStdColorPicker : public nsIColorPicker {
public:
nsStdColorPicker();
virtual ~nsStdColorPicker();
NS_DECL_ISUPPORTS
NS_DECL_NSICOLORPICKER
private:
char **mPalette;
PRInt32 mColors;
PRInt32 mNumCols;
PRInt32 mNumRows;
PRInt32 mBlockWidth;
PRInt32 mBlockHeight;
PRInt32 mFrameWidth;
PRInt32 mFrameHeight;
};
#endif /* __nsStdColorPicker_h__ */

View File

@@ -1,173 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
//
// Eric Vaughan
// Netscape Communications
//
// See documentation in associated header file
//
#include "nsTabFrame.h"
#include "nsIStyleContext.h"
#include "nsIPresContext.h"
#include "nsIContent.h"
#include "nsCOMPtr.h"
#include "nsHTMLIIDs.h"
#include "nsUnitConversion.h"
#include "nsINameSpaceManager.h"
#include "nsHTMLAtoms.h"
#include "nsXULAtoms.h"
#include "nsIReflowCommand.h"
#include <stdio.h>
//
// NS_NewToolbarFrame
//
// Creates a new Toolbar frame and returns it in |aNewFrame|
//
nsresult
NS_NewTabFrame ( nsIFrame** aNewFrame )
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsTabFrame* it = new nsTabFrame;
if (nsnull == it)
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = it;
return NS_OK;
} // NS_NewTabFrame
void
nsTabFrame::MouseClicked(nsIPresContext* aPresContext)
{
// get our index
PRInt32 index = 0;
GetIndexInParent(mContent, index);
// get the tab control
nsIContent* tabcontrol = nsnull;
GetTabControl(mContent, tabcontrol);
// get the tab panel
nsIContent* tabpanel = nsnull;
GetChildWithTag(nsXULAtoms::tabpanel, tabcontrol, tabpanel);
if (!tabpanel) {
return;
}
// unselect the old tab
// get the current index
nsAutoString v;
PRInt32 error;
tabpanel->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::index, v);
PRInt32 oldIndex = v.ToInteger(&error);
if (oldIndex != index)
{
// get the tab box
nsIContent* parent;
mContent->GetParent(parent);
// get child
nsIContent* child;
parent->ChildAt(oldIndex, child);
// set the old tab to be unselected
child->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::selected, "false", PR_TRUE);
// set the new tab to be selected
mContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::selected, "true", PR_TRUE);
}
// set the panels index
char value[100];
sprintf(value, "%d", index);
tabpanel->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::index, value, PR_TRUE);
}
nsresult
nsTabFrame::GetChildWithTag(nsIAtom* atom, nsIContent* start, nsIContent*& tabpanel)
{
// recursively search our children
PRInt32 count = 0;
start->ChildCount(count);
for (PRInt32 i = 0; i < count; i++)
{
nsIContent* child = nsnull;
start->ChildAt(i,child);
// see if it is the child
nsCOMPtr<nsIAtom> tag;
child->GetTag(*getter_AddRefs(tag));
if (tag.get() == atom)
{
tabpanel = child;
return NS_OK;
}
// recursive search the child
nsIContent* found = nsnull;
GetChildWithTag(atom, child, found);
if (found != nsnull) {
tabpanel = found;
return NS_OK;
}
}
tabpanel = nsnull;
return NS_OK;
}
nsresult
nsTabFrame::GetTabControl(nsIContent* content, nsIContent*& tabcontrol)
{
while(nsnull != content)
{
content->GetParent(content);
if (content) {
nsCOMPtr<nsIAtom> atom;
if (content->GetTag(*getter_AddRefs(atom)) == NS_OK && atom.get() == nsXULAtoms::tabcontrol) {
tabcontrol = content;
return NS_OK;
}
}
}
tabcontrol = nsnull;
return NS_OK;
}
nsresult
nsTabFrame::GetIndexInParent(nsIContent* content, PRInt32& index)
{
nsIContent* parent;
content->GetParent(parent);
return parent->IndexOf(content, index);
}

View File

@@ -1,78 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
/**
Eric D Vaughan
This class lays out its children either vertically or horizontally
**/
#ifndef nsTabFrame_h___
#define nsTabFrame_h___
#include "nsHTMLButtonControlFrame.h"
class nsTabControlFrame;
class nsTabFrame : public nsHTMLButtonControlFrame
{
public:
friend nsresult NS_NewTabFrame(nsIFrame** aNewFrame);
virtual void MouseClicked(nsIPresContext* aPresContext);
protected:
virtual nsresult GetChildWithTag(nsIAtom* atom, nsIContent* start, nsIContent*& tabpanel);
virtual nsresult GetTabControl(nsIContent* content, nsIContent*& tabcontrol);
virtual nsresult GetIndexInParent(nsIContent* content, PRInt32& index);
// Selection Methods
// XXX Doc me... (in nsIFrame.h puhleeze)
// XXX If these are selection specific, then the name should imply selection
// rather than generic event processing, e.g., SelectionHandlePress...
NS_IMETHOD HandlePress(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus) { return NS_OK; }
NS_IMETHOD HandleMultiplePress(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus) { return NS_OK; }
NS_IMETHOD HandleDrag(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus) { return NS_OK; }
NS_IMETHOD HandleRelease(nsIPresContext& aPresContext,
nsGUIEvent * aEvent,
nsEventStatus& aEventStatus) { return NS_OK; }
private:
nsTabControlFrame* mTabControlFrame;
}; // class nsTabFrame
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,180 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsTitledButtonFrame_h___
#define nsTitledButtonFrame_h___
#include "nsHTMLImageLoader.h"
#include "nsLeafFrame.h"
#include "nsIBox.h"
class nsIPopUpMenu;
class nsTitledButtonRenderer;
class nsTitledButtonFrame : public nsLeafFrame, public nsIBox
{
public:
enum CroppingStyle { CropNone, CropLeft, CropRight, CropCenter };
friend nsresult NS_NewTitledButtonFrame(nsIFrame** aNewFrame);
// nsIBox frame interface
NS_IMETHOD GetBoxInfo(nsIPresContext& aPresContext, const nsHTMLReflowState& aReflowState, nsBoxInfo& aSize);
NS_IMETHOD Dirty(nsIPresContext& aPresContext, const nsHTMLReflowState& aReflowState, nsIFrame*& incrementalChild);
NS_DECL_ISUPPORTS
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* asPrevInFlow);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint);
NS_IMETHOD GetAdditionalStyleContext(PRInt32 aIndex,
nsIStyleContext** aStyleContext) const;
NS_IMETHOD SetAdditionalStyleContext(PRInt32 aIndex,
nsIStyleContext* aStyleContext);
NS_IMETHOD DidSetStyleContext (nsIPresContext* aPresContext);
NS_IMETHOD Destroy(nsIPresContext& aPresContext);
NS_IMETHOD GetFrameName(nsString& aResult) const;
virtual void UpdateAttributes(nsIPresContext& aPresContext);
virtual void UpdateImage(nsIPresContext& aPresContext);
// nsIHTMLReflow overrides
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
~nsTitledButtonFrame();
protected:
enum CheckState { eUnset, eOff, eOn, eMixed } ;
CheckState GetCurrentCheckState();
void SetCurrentCheckState(CheckState aState);
void UpdateAccessUnderline();
virtual void MouseClicked(nsIPresContext & aPresContext);
NS_IMETHOD PaintTitle(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
NS_IMETHOD PaintImage(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
virtual void LayoutTitleAndImage(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize);
void DisplayAltFeedback(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
PRInt32 aIconId);
void DisplayAltText(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsString& aAltText,
const nsRect& aRect);
void MeasureString(const PRUnichar* aString,
PRInt32 aLength,
nscoord aMaxWidth,
PRUint32& aMaxFit,
nsIRenderingContext& aContext);
nsTitledButtonFrame();
virtual void CalculateTitleForWidth(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext, nscoord aWidth);
virtual void GetTextSize(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext, const nsString& aString, nsSize& aSize);
virtual void SetDisabled(nsAutoString aDisabled);
static nsresult UpdateImageFrame(nsIPresContext* aPresContext,
nsHTMLImageLoader* aLoader,
nsIFrame* aFrame,
void* aClosure,
PRUint32 aStatus);
void GetImageSource(nsString& aResult);
virtual void GetImageSize(nsIPresContext* aPresContext);
private:
// tri state methods
void CheckStateToString ( CheckState inState, nsString& outStateAsString ) ;
CheckState StringToCheckState ( const nsString & aStateAsString ) ;
PRBool mHasOnceBeenInMixedState;
CroppingStyle mCropType;
PRIntn mAlign;
nsString mTitle;
nsString mCroppedTitle;
nsHTMLImageLoader mImageLoader;
PRBool mSizeFrozen;
nsMargin mBorderPadding;
nsRect mImageRect;
nsRect mTitleRect;
PRBool mNeedsLayout;
nscoord mSpacing;
nsTitledButtonRenderer* mRenderer;
PRBool mHasImage;
// accesskey highlighting
PRBool mNeedsAccessUpdate;
PRInt32 mAccesskeyIndex;
nscoord mBeforeWidth, mAccessWidth, mAccessUnderlineSize, mAccessOffset;
// nsIPopUpMenu * mPopUpMenu;
// PRBool mMenuIsPoppedUp;
}; // class nsTitledButtonFrame
#endif /* nsTitledButtonFrame_h___ */

View File

@@ -1,457 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsToolbarDragListener.h"
#include "nsToolbarFrame.h"
#include "nsCOMPtr.h"
#include "nsIDOMMouseEvent.h"
#include "nsIPresContext.h"
#include "nsIContent.h"
#include "nsIDOMElement.h"
#include "nsXULAtoms.h"
#include "nsIEventStateManager.h"
#include "nsISupportsPrimitives.h"
#include "nsINameSpaceManager.h"
#include "nsIDOMXULDocument.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"
NS_IMPL_ADDREF(nsToolbarDragListener)
NS_IMPL_RELEASE(nsToolbarDragListener)
//
// nsToolbarDragListener ctor
//
// Init member variables. We can't really do much of anything important here because
// any subframes might not be totally intialized yet, or in the hash table
//
nsToolbarDragListener :: nsToolbarDragListener ( nsToolbarFrame* inToolbar, nsIPresContext* inPresContext )
: mToolbar(inToolbar), mPresContext(inPresContext), mCurrentDropLoc(-1)
{
NS_INIT_REFCNT();
// we really need this all over the place. just be safe that we have it.
NS_ASSERTION ( mPresContext, "no pres context set on toolbar drag listener" );
} // nsToolbarDragListener ctor
//
// nsToolbarDragListener dtor
//
// Cleanup.
//
nsToolbarDragListener::~nsToolbarDragListener()
{
}
//
// QueryInterface
//
// Modeled after scc's reference implementation
// http://www.mozilla.org/projects/xpcom/QI.html
//
nsresult
nsToolbarDragListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if ( !aInstancePtr)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsCOMTypeInfo<nsIDOMEventListener>::GetIID()))
*aInstancePtr = NS_STATIC_CAST(nsIDOMEventListener*, NS_STATIC_CAST(nsIDOMDragListener*, this));
else if (aIID.Equals(nsCOMTypeInfo<nsIDOMDragListener>::GetIID()))
*aInstancePtr = NS_STATIC_CAST(nsIDOMDragListener*, this);
else if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
*aInstancePtr = NS_STATIC_CAST(nsISupports*, NS_STATIC_CAST(nsIDOMDragListener*, this));
else
*aInstancePtr = 0;
nsresult status;
if ( !*aInstancePtr )
status = NS_NOINTERFACE;
else {
NS_ADDREF( NS_REINTERPRET_CAST(nsISupports*, *aInstancePtr) );
status = NS_OK;
}
return status;
}
////////////////////////////////////////////////////////////////////////
nsresult
nsToolbarDragListener::HandleEvent(nsIDOMEvent* aEvent)
{
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
nsresult
nsToolbarDragListener::DragGesture(nsIDOMEvent* aDragEvent)
{
// this code should all be in JS.
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
nsresult
nsToolbarDragListener::DragEnter(nsIDOMEvent* aDragEvent)
{
// We don't need to do anything special here. If anything does need to be done,
// the code should all be in JS.
return NS_OK;
}
//
// ItemMouseIsOver
//
// Figure out which child item mouse is over. |outIndex| is the index of the item the object
// should be dropped _before_. Therefore if the item should be dropped at the end, the index
// will be greater than the number of items in the list. |outOnChild| is true if the item
// is a container and the drop would be "on" that item.
//
void
nsToolbarDragListener :: ItemMouseIsOver ( nsIDOMEvent* aDragEvent, nscoord* outXLoc,
PRUint32* outIndex, PRBool* outOnChild )
{
*outOnChild = PR_FALSE;
// figure out which frame is the right one for determining the drop feedback. Do we
// want to do this every time? We certainly can't do it upon toolbar creation (hash
// tables not setup at that time), so we're forced to do it now. What happens if while
// we're dragging some rule gets fired that causes the frame to go away?
nsIFrame* dropAreaFrame = LocateDropAreaFrame();
if ( !dropAreaFrame ) {
// gaaak, we're doomed.
outIndex = 0;
outXLoc = 0;
return;
}
//
// Get the mouse coordinates from the DOM event, but they will be in the
// window/widget coordinate system. We must first get them into the frame-relative
// coordinate system. Yuck.
//
// get mouse coordinates and translate them into twips
nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aDragEvent));
PRInt32 x,y = 0;
mouseEvent->GetClientX(&x);
mouseEvent->GetClientY(&y);
float p2t;
mPresContext->GetScaledPixelsToTwips(&p2t);
nscoord onePixel = NSIntPixelsToTwips(1, p2t);
nscoord xp = NSIntPixelsToTwips(x, p2t);
nscoord yp = NSIntPixelsToTwips(y, p2t);
// compute the offset to top level in twips
PRInt32 frameOffsetX = 0, frameOffsetY = 0;
nsIFrame* curr = dropAreaFrame;
curr->GetParent(&curr);
float t2p;
mPresContext->GetTwipsToPixels(&t2p);
while ( curr ) {
nsPoint origin;
curr->GetOrigin(origin); // in twips
frameOffsetX += origin.x; // build the offset incrementally
frameOffsetY += origin.y;
curr->GetParent(&curr); // moving up the chain
} // until we reach the top
// subtract the offset from the x,y coord to put into frame relative coordinates.
xp -= frameOffsetX;
yp -= frameOffsetY;
nsPoint pnt(xp, yp);
// get the toolbar's rect
nsRect tbRect;
dropAreaFrame->GetRect(tbRect);
PRUint32 count = 0;
PRBool found = PR_FALSE;
nsIFrame* childFrame;
nsRect rect; // child frame's rect
nsRect prevRect(-1, -1, 0, 0);
//
// Now loop through the child and see if the mouse is over a child
//
dropAreaFrame->FirstChild(nsnull, &childFrame);
while ( childFrame ) {
// The mouse coords are in the toolbar's domain
// Get child's rect and adjust to the toolbar's domain
childFrame->GetRect(rect);
rect.MoveBy(tbRect.x, tbRect.y);
// remember the previous child x location
if (pnt.x < rect.x && prevRect.x == -1)
prevRect = rect;
// now check to see if the mouse inside an items bounds
if (rect.Contains(pnt)) {
nsCOMPtr<nsIContent> content;
childFrame->GetContent(getter_AddRefs(content));
if ( content ) {
nsCOMPtr<nsIAtom> tag;
content->GetTag(*getter_AddRefs(tag));
// for now I am checking for both titlebutton and toolbar items
// XXX but the check for titlebutton should be removed in the future
if (tag.get() == nsXULAtoms::titledbutton || tag.get() == nsXULAtoms::toolbaritem) {
// now check if item is a container
PRBool isContainer = PR_FALSE;
nsCOMPtr<nsIDOMElement> domElement ( do_QueryInterface(content) );
if ( domElement ) {
nsAutoString value;
domElement->GetAttribute(nsAutoString("container"), value); // can't use an atom here =(
isContainer = value.Equals("true");
}
else
NS_WARNING("Not a DOM element");
// if we have a container, the area is broken up into 3 pieces (left, middle, right). If
// it isn't it's only broken up into two (left and right)
PRInt32 xc = -1;
if ( isContainer ) {
if (pnt.x <= (rect.x + (rect.width / 4))) {
*outIndex = count;
xc = rect.x - tbRect.x;
}
else if (pnt.x >= (rect.x + PRInt32(float(rect.width) *0.75))) {
*outIndex = count + 1;
xc = rect.x - tbRect.x + rect.width - onePixel;
}
else {
// we're on a container, don't draw anything so xc shouldn't get set.
*outIndex = count;
*outOnChild = PR_TRUE;
}
} else {
if (pnt.x <= (rect.x + (rect.width / 2))) {
*outIndex = count;
xc = rect.x - tbRect.x;
}
else {
*outIndex = count + 1;
xc = rect.x - tbRect.x + rect.width + onePixel;
}
}
*outXLoc = xc;
}
else {
// mouse is over something (probably a spacer) so return the left side of
// the spacer.
*outXLoc = rect.x - tbRect.x;
*outIndex = count;
}
// found something, break out of the loop
found = PR_TRUE;
break;
}
} // if mouse is in an item
nsresult rv = childFrame->GetNextSibling(&childFrame);
NS_ASSERTION(rv == NS_OK,"failed to get next child");
count++;
} // foreach child
if (!found) {
*outIndex = count; // already incremented past last item
if ( count )
*outXLoc = prevRect.x - tbRect.x + rect.width + onePixel;
else
*outXLoc = onePixel;
}
}
//
// DragOver
//
// The mouse has moved over the toolbar while a drag is happening. We really just want to
// "annotate" the toolbar with the current drop location. We don't want to make any judgement
// as this stage as to whether or not the drag should be accepted or draw any feedback.
//
nsresult
nsToolbarDragListener::DragOver(nsIDOMEvent* aDragEvent)
{
#if 0
nsCOMPtr<nsIContent> c;
mToolbar->GetContent ( getter_AddRefs(c) );
nsCOMPtr<nsIDOMNode> d ( do_QueryInterface(c) );
nsCOMPtr<nsIDOMNode> t;
aDragEvent->GetTarget ( getter_AddRefs(t) );
printf ( "DRAGOVER:: toolbar content is %ld, as DOMNode %ld, target is %ld\n", c, d, t );
#endif
// Check to see if the mouse is over an item and which one it is.
nscoord xLoc = 0;
PRBool onChild;
PRUint32 beforeIndex = 0;
ItemMouseIsOver(aDragEvent, &xLoc, &beforeIndex, &onChild);
if ( xLoc != mCurrentDropLoc ) {
// stash the new location in the toolbar's content model. Note that the toolbar code doesn't
// care at all about "tb-droplocation", only the coordinate so there is no need to send the
// AttributeChanged() about that attribute.
nsCOMPtr<nsIContent> content;
mToolbar->GetContent ( getter_AddRefs(content) );
if ( content ) {
char buffer[10];
// need the cast, because on some platforms, PR[U]int32 != long, but we're using "%ld"
sprintf(buffer, "%ld", NS_STATIC_CAST(long, xLoc));
content->SetAttribute ( kNameSpaceID_None, nsXULAtoms::tbDropLocationCoord, buffer, PR_TRUE );
sprintf(buffer, "%ld", NS_STATIC_CAST(long, beforeIndex));
content->SetAttribute ( kNameSpaceID_None, nsXULAtoms::tbDropLocation, "1", PR_FALSE );
content->SetAttribute ( kNameSpaceID_None, nsXULAtoms::tbDropOn, onChild ? "true" : "false", PR_FALSE );
}
// cache the current drop location
mCurrentDropLoc = xLoc;
}
// NS_OK means event is NOT consumed. We want to make sure JS gets this so it
// can determine if the drag is allowed.
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
nsresult
nsToolbarDragListener::DragExit(nsIDOMEvent* aDragEvent)
{
// there are some bugs that cause us to not be able to correctly track dragExit events
// so until then we just get on our knees and pray we don't get fooled again.
#if 0
nsCOMPtr<nsIContent> c;
mToolbar->GetContent ( getter_AddRefs(c) );
nsCOMPtr<nsIDOMNode> d ( do_QueryInterface(c) );
nsCOMPtr<nsIDOMNode> t;
aDragEvent->GetTarget ( getter_AddRefs(t) );
printf ( "DRAGEXIT:: toolbar DOMNode %ld, target is %ld\n", d, t );
nsCOMPtr<nsIContent> content;
mToolbar->GetContent ( getter_AddRefs(content) );
// we will get a drag exit event on sub items because we catch the event on the way down. If
// the target is not our toolbar, then ignore it.
nsCOMPtr<nsIDOMNode> toolbarDOMNode ( do_QueryInterface(content) );
nsCOMPtr<nsIDOMNode> eventTarget;
aDragEvent->GetTarget ( getter_AddRefs(eventTarget) );
if ( eventTarget != toolbarDOMNode )
return NS_OK;
printf("***REAL EXIT EVENT\n");
// tell the toolbar to not do any more drop feedback. Note that the toolbar code doesn't
// care at all about "tb-droplocation", only the coordinate so there is no need to send the
// AttributeChanged() about that attribute.
char buffer[10];
sprintf(buffer, "%ld", -1);
content->SetAttribute ( kNameSpaceID_None, nsXULAtoms::tbDropLocationCoord, buffer, PR_TRUE );
content->SetAttribute ( kNameSpaceID_None, nsXULAtoms::tbDropLocation, buffer, PR_FALSE );
// cache the current drop location
mCurrentDropLoc = -1;
#endif
return NS_OK; // don't consume event
}
////////////////////////////////////////////////////////////////////////
nsresult
nsToolbarDragListener::DragDrop(nsIDOMEvent* aMouseEvent)
{
// this code should all be in JS.
return NS_OK;
}
//
// LocateDropAreaFrame
//
// Returns the frame (or subframe) that contains the buttons that can be dragged.
// Either it will be the toolbar frame as a whole, or it will be some subframe of the bar id'd by
// the |dragdroparea| attribute.
//
nsIFrame*
nsToolbarDragListener :: LocateDropAreaFrame ( )
{
nsIFrame* retVal = nsnull;
// is a subframe the drag/drop area? determine if the attribute is set.
nsString dropAreaID;
PRBool dropAreaIsSubframe = PR_FALSE;
nsCOMPtr<nsIContent> toolbarContent;
mToolbar->GetContent ( getter_AddRefs(toolbarContent) );
if ( toolbarContent ) {
if ( toolbarContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::tbDragDropArea, dropAreaID) == NS_CONTENT_ATTR_HAS_VALUE )
dropAreaIsSubframe = PR_TRUE;
}
// if there is a named subframe, go find it, otherwise use the entire toolbar
if ( dropAreaIsSubframe ) {
// get the presShell so we can call GetPrimaryFrameFor later.
nsCOMPtr<nsIPresShell> presShell;
mPresContext->GetShell ( getter_AddRefs(presShell) );
// get the document so we can get do a GetElementByID.
nsCOMPtr<nsIDocument> document;
toolbarContent->GetDocument ( *getter_AddRefs(document) );
if ( document ) {
nsCOMPtr<nsIDOMXULDocument> xulDoc ( do_QueryInterface(document) );
if ( xulDoc ) {
nsCOMPtr<nsIDOMElement> domElementOfSubframe;
xulDoc->GetElementById ( dropAreaID, getter_AddRefs(domElementOfSubframe) );
// finally get the frame associated with that dom node
nsCOMPtr<nsIContent> contentOfSubframe ( do_QueryInterface(domElementOfSubframe) );
if ( contentOfSubframe && presShell )
presShell->GetPrimaryFrameFor ( contentOfSubframe, &retVal );
}
}
} // if named subframe
else
retVal = mToolbar;
NS_ASSERTION ( retVal, "toolbar drag listener couldn't figure out the drag area." );
return retVal;
} // LocateDropAreaFrame

View File

@@ -1,70 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsToolbarDragListener_h__
#define nsToolbarDragListener_h__
#include "nsIDOMDragListener.h"
#include "nsCoord.h"
class nsToolbarFrame;
class nsIPresContext;
class nsIDOMEvent;
class nsIFrame;
class nsToolbarDragListener : public nsIDOMDragListener
{
public:
// default ctor and dtor
nsToolbarDragListener ( nsToolbarFrame* inToolbar, nsIPresContext* inPresContext );
virtual ~nsToolbarDragListener();
// interfaces for addref and release and queryinterface
NS_DECL_ISUPPORTS
// nsIDOMDragListener
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
virtual nsresult DragEnter(nsIDOMEvent* aDragEvent);
virtual nsresult DragOver(nsIDOMEvent* aDragEvent);
virtual nsresult DragExit(nsIDOMEvent* aDragEvent);
virtual nsresult DragDrop(nsIDOMEvent* aDragEvent);
virtual nsresult DragGesture(nsIDOMEvent* aDragEvent);
protected:
// Figure out which child item mouse is over. |outIndex| is the index of the item the object
// should be dropped _before_. Therefore if the item should be dropped at the end, the index
// will be greater than the number of items in the list. |outOnChild| is true if the item
// is a container and the drop would be "on" that item.
void ItemMouseIsOver(nsIDOMEvent* aDragEvent, nscoord* outXLoc, PRUint32* outIndex, PRBool* outOnChild);
// Find the frame (or subframe) that contains the buttons that can be dragged.
nsIFrame* LocateDropAreaFrame ( ) ;
nsToolbarFrame * mToolbar; // toolbar owns me, don't be circular
nsIPresContext * mPresContext; // weak reference
PRInt32 mCurrentDropLoc;
}; // class nsToolbarDragListener
#endif

View File

@@ -1,449 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
//
// Mike Pinkerton
// Netscape Communications
//
// See documentation in associated header file
//
#include "nsToolbarFrame.h"
#include "nsCSSRendering.h"
#include "nsToolbarDragListener.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMDragListener.h"
#include "nsIContent.h"
#include "nsIPresContext.h"
#include "nsIStyleContext.h"
#include "nsIViewManager.h"
#include "nsXULAtoms.h"
#include "nsINameSpaceManager.h"
#define TEMP_HACK_FOR_BUG_11291 1
#if TEMP_HACK_FOR_BUG_11291
// for temp fix of bug 11291. This should really be in JavaScript, I think.
#include "nsIDOMNodeList.h"
#include "nsIDOMElement.h"
class nsTEMPDragGestureEater : public nsIDOMDragListener
{
public:
// default ctor and dtor
nsTEMPDragGestureEater ( ) ;
virtual ~nsTEMPDragGestureEater() { };
// interfaces for addref and release and queryinterface
NS_DECL_ISUPPORTS
// nsIDOMMouseListener
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
virtual nsresult DragEnter(nsIDOMEvent* aMouseEvent);
virtual nsresult DragOver(nsIDOMEvent* aMouseEvent);
virtual nsresult DragExit(nsIDOMEvent* aMouseEvent);
virtual nsresult DragDrop(nsIDOMEvent* aMouseEvent);
virtual nsresult DragGesture(nsIDOMEvent* aMouseEvent);
}; // class nsTEMPDragGestureEater
NS_IMPL_ADDREF(nsTEMPDragGestureEater)
NS_IMPL_RELEASE(nsTEMPDragGestureEater)
nsTEMPDragGestureEater :: nsTEMPDragGestureEater ( )
{
NS_INIT_REFCNT();
}
//
// QueryInterface
//
// Modeled after scc's reference implementation
// http://www.mozilla.org/projects/xpcom/QI.html
//
nsresult
nsTEMPDragGestureEater::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if ( !aInstancePtr)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsCOMTypeInfo<nsIDOMEventListener>::GetIID()))
*aInstancePtr = NS_STATIC_CAST(nsIDOMEventListener*, this);
else if (aIID.Equals(nsCOMTypeInfo<nsIDOMDragListener>::GetIID()))
*aInstancePtr = NS_STATIC_CAST(nsIDOMDragListener*, this);
else if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
*aInstancePtr = NS_STATIC_CAST(nsISupports*, NS_STATIC_CAST(nsIDOMDragListener*, this));
else
*aInstancePtr = 0;
nsresult status;
if ( !*aInstancePtr )
status = NS_NOINTERFACE;
else {
NS_ADDREF( NS_REINTERPRET_CAST(nsISupports*, *aInstancePtr) );
status = NS_OK;
}
return status;
}
nsresult
nsTEMPDragGestureEater :: HandleEvent(nsIDOMEvent* aEvent)
{
return NS_OK;
}
nsresult
nsTEMPDragGestureEater::DragGesture(nsIDOMEvent* aMouseEvent)
{
// we want the text widget to see this event, but not anyone above us that
// might be registered as a listener for drags. Therefore, don't
// allow this event to bubble.
aMouseEvent->PreventBubble();
return NS_ERROR_BASE; // means I AM consuming event
}
nsresult
nsTEMPDragGestureEater::DragEnter(nsIDOMEvent* aMouseEvent)
{
return NS_OK; // means I am NOT consuming event
}
nsresult
nsTEMPDragGestureEater::DragOver(nsIDOMEvent* aMouseEvent)
{
return NS_OK; // means I am NOT consuming event
}
nsresult
nsTEMPDragGestureEater::DragExit(nsIDOMEvent* aMouseEvent)
{
return NS_OK; // means I am NOT consuming event
}
nsresult
nsTEMPDragGestureEater::DragDrop(nsIDOMEvent* aMouseEvent)
{
return NS_OK; // means I am NOT consuming event
}
#endif /* TEMP_HACK_FOR_BUG_11291 */
#ifdef XP_MAC
#pragma mark -
#endif
//
// NS_NewToolbarFrame
//
// Creates a new Toolbar frame and returns it in |aNewFrame|
//
nsresult
NS_NewToolbarFrame ( nsIFrame** aNewFrame )
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsToolbarFrame* it = new nsToolbarFrame;
if (nsnull == it)
return NS_ERROR_OUT_OF_MEMORY;
// it->SetFlags(aFlags);
* aNewFrame = it;
return NS_OK;
} // NS_NewToolbarFrame
//
// nsToolbarFrame ctor
//
// Most of the work need to be delayed until Init(). Lame!
//
nsToolbarFrame :: nsToolbarFrame ( )
: mXDropLoc ( -1 )
{
}
//
// nsToolbarFrame dtor
//
// Cleanup. Remove our registered event listener from the content model.
//
nsToolbarFrame :: ~nsToolbarFrame ( )
{
nsCOMPtr<nsIContent> content;
GetContent(getter_AddRefs(content));
nsCOMPtr<nsIDOMEventReceiver> reciever(do_QueryInterface(content));
// NOTE: the Remove will delete the drag listener
reciever->RemoveEventListenerByIID((nsIDOMDragListener *)mDragListener, nsIDOMDragListener::GetIID());
}
//
// Init
//
// Setup event listeners for drag and drop. Our frame's lifetime is bounded by the
// lifetime of the content model, so we're guaranteed that the content node won't go away on us. As
// a result, our drag listener can't go away before the frame is deleted. Since the content
// node holds owning references to our drag listener, which we tear down in the dtor, there is no
// need to hold an owning ref to it ourselves.
//
NS_IMETHODIMP
nsToolbarFrame::Init ( nsIPresContext& aPresContext, nsIContent* aContent,
nsIFrame* aParent, nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
nsCOMPtr<nsIContent> content;
GetContent(getter_AddRefs(content));
nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(content));
// register our drag over and exit capturers. These annotate the content object
// with enough info to determine where the drop would happen so that JS can
// do the right thing.
mDragListener = new nsToolbarDragListener(this, &aPresContext);
receiver->AddEventListener("dragover", mDragListener, PR_TRUE);
receiver->AddEventListener("dragexit", mDragListener, PR_TRUE);
#if 0 //TEMP_HACK_FOR_BUG_11291
// Ok, this is a hack until Ender lands. We need to have a mouse listener on text widgets
// in order to make sure that mouseDowns within the text widget don't bubble up to the toolbar
// listener. This would cause problems where selecting text and moving the mouse outside the text
// widget and into the toolbar would start a drag (bug #11291)
nsCOMPtr<nsIDOMElement> element ( do_QueryInterface(content) );
if ( element ) {
nsCOMPtr<nsIDOMNodeList> inputList;
element->GetElementsByTagName("INPUT", getter_AddRefs(inputList));
if ( inputList ) {
PRUint32 length = 0;
inputList->GetLength(&length);
for ( PRUint32 i = 0; i < length; ++i ) {
nsCOMPtr<nsIDOMNode> node;
inputList->Item(i, getter_AddRefs(node));
receiver = do_QueryInterface(node);
if ( receiver )
receiver->AddEventListenerByIID(new nsTEMPDragGestureEater, nsIDOMDragListener::GetIID());
// yes, i know this will leak. That's ok, i don't care because this code will go away
}
}
}
#endif
return rv;
}
//
// Paint
//
// Paint our background and border like normal frames, but before we draw the
// children, draw our grippies for each toolbar.
//
NS_IMETHODIMP
nsToolbarFrame :: Paint ( nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)
{
nsresult res = nsBoxFrame::Paint ( aPresContext, aRenderingContext, aDirtyRect, aWhichLayer );
if (mXDropLoc != -1) {
// XXX this is temporary
if (!mMarkerStyle) {
nsCOMPtr<nsIAtom> atom ( getter_AddRefs(NS_NewAtom(":-moz-drop-marker")) );
aPresContext.ProbePseudoStyleContextFor(mContent, atom, mStyleContext,
PR_FALSE, getter_AddRefs(mMarkerStyle));
}
nscolor color;
if (mMarkerStyle) {
const nsStyleColor* styleColor = (const nsStyleColor*)mMarkerStyle->GetStyleData(eStyleStruct_Color);
color = styleColor->mColor;
} else {
color = NS_RGB(0,0,0);
}
// draw different drop feedback depending on if we have subitems or not
int numChildren = 0;
mContent->ChildCount(numChildren);
if ( numChildren ) {
aRenderingContext.SetColor(color);
nsRect dividingLine ( mXDropLoc, 0, 40, mRect.height );
aRenderingContext.FillRect(dividingLine);
}
else
aRenderingContext.DrawRect ( mRect );
}
return res;
} // Paint
//
// GetFrameForPoint
//
// Override to process events in our own frame
//
NS_IMETHODIMP
nsToolbarFrame :: GetFrameForPoint ( nsIPresContext* aPresContext,
const nsPoint& aPoint,
nsIFrame** aFrame)
{
nsresult retVal = nsHTMLContainerFrame::GetFrameForPoint(aPresContext, aPoint, aFrame);
// returning NS_OK means that we tell the frame finding code that we have something
// and to stop looking elsewhere for a frame.
if ( aFrame && *aFrame == this )
retVal = NS_OK;
else if ( retVal != NS_OK ) {
*aFrame = this;
retVal = NS_OK;
}
return retVal;
} // GetFrameForPoint
//
// HandleEvent
//
// Process events that come to this frame. If they end up here, they are
// almost certainly drag and drop events.
//
NS_IMETHODIMP
nsToolbarFrame :: HandleEvent ( nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
if ( !aEvent )
return nsEventStatus_eIgnore;
switch (aEvent->message) {
case NS_DRAGDROP_ENTER:
if (!mMarkerStyle) {
nsCOMPtr<nsIAtom> atom ( getter_AddRefs(NS_NewAtom(":-moz-drop-marker")) );
aPresContext.ProbePseudoStyleContextFor(mContent, atom, mStyleContext,
PR_FALSE,
getter_AddRefs(mMarkerStyle));
}
break;
}
//XXX this needs to change when I am really handling the D&D events
return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
} // HandleEvent
#if NOT_YET_NEEDED
/**
* Call this when styles change
*/
void
nsToolbarFrame::ReResolveStyles(nsIPresContext& aPresContext,
PRInt32 aParentChange,
nsStyleChangeList* aChangeList,
PRInt32* aLocalChange)
{
// style that draw an Marker around the button
// see if the Marker has changed.
/*nsCOMPtr<nsIStyleContext> oldMarker = mMarkerStyle;
nsCOMPtr<nsIAtom> atom ( getter_AddRefs(NS_NewAtom(":-moz-marker")) );
aPresContext.ProbePseudoStyleContextFor(mContent, atom, mStyleContext,
PR_FALSE,
getter_AddRefs(mMarkerStyle));
if ((mMarkerStyle && oldMarker) && (mMarkerStyle != oldMarker)) {
nsFrame::CaptureStyleChangeFor(this, oldMarker, mMarkerStyle,
aParentChange, aChangeList, aLocalChange);
}*/
}
#endif
////////////////////////////////////////////////////////////////////////
// This is temporary until the bubling of event for CSS actions work
////////////////////////////////////////////////////////////////////////
static void ForceDrawFrame(nsIPresContext* aPresContext, nsIFrame * aFrame);
static void ForceDrawFrame(nsIPresContext* aPresContext, nsIFrame * aFrame)
{
if (aFrame == nsnull) {
return;
}
nsRect rect;
nsIView * view;
nsPoint pnt;
aFrame->GetOffsetFromView(aPresContext, pnt, &view);
aFrame->GetRect(rect);
rect.x = pnt.x;
rect.y = pnt.y;
if (view) {
nsCOMPtr<nsIViewManager> viewMgr;
view->GetViewManager(*getter_AddRefs(viewMgr));
if (viewMgr)
viewMgr->UpdateView(view, rect, NS_VMREFRESH_AUTO_DOUBLE_BUFFER | NS_VMREFRESH_IMMEDIATE);
}
}
//
// AttributeChanged
//
// Track several attributes set by the d&d drop feedback tracking mechanism. The first
// is the "tb-triggerrepaint" attribute so JS can trigger a repaint when it
// needs up update the drop feedback. The second is the x (or y, if bar is vertical)
// coordinate of where the drop feedback bar should be drawn.
//
NS_IMETHODIMP
nsToolbarFrame :: AttributeChanged ( nsIPresContext* aPresContext, nsIContent* aChild,
PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRInt32 aHint)
{
nsresult rv = NS_OK;
if ( aAttribute == nsXULAtoms::tbTriggerRepaint )
ForceDrawFrame ( aPresContext, this );
else if ( aAttribute == nsXULAtoms::tbDropLocationCoord ) {
nsAutoString attribute;
aChild->GetAttribute ( kNameSpaceID_None, aAttribute, attribute );
char* iHateNSString = attribute.ToNewCString();
mXDropLoc = atoi( iHateNSString );
nsAllocator::Free ( iHateNSString );
}
else
rv = nsBoxFrame::AttributeChanged ( aPresContext, aChild, aNameSpaceID, aAttribute, aHint );
return rv;
} // AttributeChanged

View File

@@ -1,119 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
//
// Mike Pinkerton
// Netscape Communications
//
// nsToolbarFrame is a layout object that contains items (specified as
// children in the DOM). The layout for toolbars is a little complicated, but
// it basically just lays out its children in as a box. Toolbars themselves
// don't know anything about grippies (as in 4.x) but are associated with them
// through toolboxes. This allows a developer to create a standalone toolbar
// (for inclusion in a webpage), which obviously doesn't need to have a grippy.
//
// As mentioned above, the Toolbar expects its toolbars to be its children in
// the DOM. The exact structure of the children is documented on:
// http://www.mozilla.org/xpfe/DMWSpecNew.html
//
// This implementation of toolbars now uses evaughan's box code for layout
// of its children and to determine its size.
//
#ifndef nsToolbarFrame_h__
#define nsToolbarFrame_h__
#define TOOLBARITEM_MIME "moz/toolbaritem"
#define TOOLBAR_MIME "moz/toolbar"
#include "nsCOMPtr.h"
#include "nsBoxFrame.h"
#include "nsIStyleContext.h"
class nsIContent;
class nsIPresContext;
class nsIFrame;
class nsToolbarDragListener;
class nsToolbarFrame : public nsBoxFrame
{
public:
friend nsresult NS_NewToolbarFrame(nsIFrame** aNewFrame);
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* asPrevInFlow);
// nsIHTMLReflow overrides
NS_IMETHOD Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
// nsFrame overrides
NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext,
const nsPoint& aPoint, // Overridden to capture events
nsIFrame** aFrame);
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint) ;
#if WTF_IS_THIS
//¥¥¥ not sure at all where this comes from. I asked rods, no reply yet.
virtual void ReResolveStyles(nsIPresContext& aPresContext,
PRInt32 aParentChange,
nsStyleChangeList* aChangeList,
PRInt32* aLocalChange);
#endif
#if 0
void SetDropfeedbackLocation(nscoord aX) { mXDropLoc = aX; }
#endif
protected:
nsToolbarFrame();
virtual ~nsToolbarFrame();
// pass-by-value not allowed for a coordinator because it corresponds 1-to-1
// with an element in the UI.
nsToolbarFrame ( const nsToolbarFrame& aFrame ) ; // DO NOT IMPLEMENT
nsToolbarFrame& operator= ( const nsToolbarFrame& aFrame ) ; // DO NOT IMPLEMENT
// our event handler registered with the content model. See the discussion
// in Init() for why this is a weak ref.
nsToolbarDragListener* mDragListener;
// only used during drag and drop for drop feedback. These are not
// guaranteed to be meaningful when no drop is underway.
PRInt32 mXDropLoc;
nsCOMPtr<nsIStyleContext> mMarkerStyle;
}; // class nsToolbarFrame
#endif

View File

@@ -1,172 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsToolbarItemFrame.h"
#include "nsCOMPtr.h"
#include "nsWidgetsCID.h"
// Drag & Drop, Clipboard Support
static NS_DEFINE_CID(kCDragServiceCID, NS_DRAGSERVICE_CID);
static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID);
static NS_DEFINE_IID(kCDataFlavorCID, NS_DATAFLAVOR_CID);
//
// NS_NewToolbarItemFrame (friend)
//
// Creates a new toolbar item frame and returns it in |aNewFrame|
//
nsresult
NS_NewToolbarItemFrame ( nsIFrame** aNewFrame )
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if ( !aNewFrame )
return NS_ERROR_NULL_POINTER;
nsToolbarItemFrame* it = new nsToolbarItemFrame;
if ( !it )
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = it;
return NS_OK;
} // NS_NewToolbarItemFrame
//
// nsToolbarItemFrame ctor and dtor
//
nsToolbarItemFrame::nsToolbarItemFrame()
{
}
nsToolbarItemFrame::~nsToolbarItemFrame()
{
}
//
// Init
//
// Ummm, just forwards for now.
//
NS_IMETHODIMP
nsToolbarItemFrame::Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
return rv;
}
//
// Init
//
// Ummm, just forwards for now. Most of this code is now in the drag listener's
// mouseMoved event.
//
// ¥¥¥ remove all this.
//
NS_IMETHODIMP
nsToolbarItemFrame::HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
// if disabled do nothing
/*if (PR_TRUE == mRenderer.isDisabled()) {
return NS_OK;
}
switch (aEvent->message) {
case NS_KEY_PRESS:
if (NS_KEY_EVENT == aEvent->eventStructType) {
nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
if (NS_VK_SPACE == keyEvent->keyCode || NS_VK_RETURN == keyEvent->keyCode) {
MouseClicked(aPresContext);
}
}
break;
case NS_MOUSE_LEFT_CLICK:
MouseClicked(aPresContext);
break;
}
*/
/* // Start Drag
nsIDragService* dragService;
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
nsIDragService::GetIID(),
(nsISupports **)&dragService);
if (NS_OK == rv) {
nsCOMPtr<nsITransferable> trans;
rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
nsITransferable::GetIID(), getter_AddRefs(trans));
nsCOMPtr<nsITransferable> trans2;
rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
nsITransferable::GetIID(), getter_AddRefs(trans2));
if ( trans && trans2 ) {
nsString textPlainFlavor ( "text/plain" );
trans->AddDataFlavor(&textPlainFlavor);
nsString dragText = "Drag Text";
PRUint32 len = 9;
trans->SetTransferData(&textPlainFlavor, dragText.ToNewCString(), len); // transferable consumes the data
trans2->AddDataFlavor(&textPlainFlavor);
nsString dragText2 = "More Drag Text";
len = 14;
trans2->SetTransferData(&textPlainFlavor, dragText2.ToNewCString(), len); // transferable consumes the data
nsCOMPtr<nsISupportsArray> items;
NS_NewISupportsArray(getter_AddRefs(items));
if ( items ) {
items->AppendElement(trans);
items->AppendElement(trans2);
dragService->InvokeDragSession(items, nsnull, nsIDragService::DRAGDROP_ACTION_COPY | nsIDragService::DRAGDROP_ACTION_MOVE);
}
}
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
} */
printf("ToolbarItem %d\n", aEvent->message);
return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
}
/*
* We are a frame and we do not maintain a ref count
*/
NS_IMETHODIMP_(nsrefcnt)
nsToolbarItemFrame::AddRef(void)
{
return NS_OK;
}
NS_IMETHODIMP_(nsrefcnt)
nsToolbarItemFrame::Release(void)
{
return NS_OK;
}

View File

@@ -1,56 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsToolbarItemFrame_h___
#define nsToolbarItemFrame_h___
#include "nsBoxFrame.h"
class nsIFrame;
class nsIPresContext;
class nsIStyleContext;
class nsToolbarItemFrame : public nsBoxFrame
{
public:
nsToolbarItemFrame();
~nsToolbarItemFrame();
friend nsresult NS_NewToolbarItemFrame(nsIFrame** aNewFrame);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* asPrevInFlow);
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
}; // class nsToolbarItemFrame
#endif /* nsToolbarItemFrame_h___ */

View File

@@ -1,932 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
//
// Mike Pinkerton
// Netscape Communications
//
// Significant portions of the collapse/expanding code donated by Chris Lattner
// (sabre@skylab.org). Thanks Chris!
//
// See documentation in associated header file
//
#include "nsToolboxFrame.h"
#include "nsToolbarFrame.h" // needed for MIME definitions
#include "nsIStyleContext.h"
#include "nsCSSRendering.h"
#include "nsIReflowCommand.h"
#include "nsHTMLIIDs.h"
#include "nsIPresContext.h"
#include "nsIWidget.h"
#include "nsINameSpaceManager.h"
#include "nsIServiceManager.h"
#include "nsWidgetsCID.h"
#include "nsIDragService.h"
#include "nsIDragSession.h"
#include "nsITransferable.h"
#include "nsIFormatConverter.h"
#include "nsCOMPtr.h"
#include "nsIDOMUIEvent.h"
#include "nsIDOMDragListener.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMEventListener.h"
#include "nsISupportsPrimitives.h"
#include "nsISupportsArray.h"
// Drag & Drop, Clipboard Support
static NS_DEFINE_CID(kCDragServiceCID, NS_DRAGSERVICE_CID);
static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID);
static NS_DEFINE_IID(kCDataFlavorCID, NS_DATAFLAVOR_CID);
static NS_DEFINE_IID(kCXIFFormatConverterCID, NS_XIFFORMATCONVERTER_CID);
NS_IMPL_ADDREF(nsToolboxFrame::DragListenerDelegate);
NS_IMPL_RELEASE(nsToolboxFrame::DragListenerDelegate);
NS_IMETHODIMP
nsToolboxFrame::DragListenerDelegate::QueryInterface(REFNSIID aIID, void** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsCOMTypeInfo<nsIDOMDragListener>::GetIID()) ||
aIID.Equals(nsCOMTypeInfo<nsIDOMEventListener>::GetIID()) ||
aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
*aResult = NS_STATIC_CAST(nsIDOMDragListener*, this);
NS_ADDREF_THIS();
return NS_OK;
}
else {
*aResult = nsnull;
return NS_NOINTERFACE;
}
}
//
// NS_NewToolboxFrame
//
// Creates a new toolbox frame and returns it in |aNewFrame|
//
nsresult
NS_NewToolboxFrame ( nsIFrame** aNewFrame )
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsToolboxFrame* it = new nsToolboxFrame;
if (nsnull == it)
return NS_ERROR_OUT_OF_MEMORY;
//it->SetFlags(aFlags);
*aNewFrame = it;
return NS_OK;
} // NS_NewToolboxFrame
//
// nsToolboxFrame cntr
//
// Init, if necessary
//
nsToolboxFrame :: nsToolboxFrame ( )
: mSumOfToolbarHeights(0), mNumToolbars(0),
mGrippyHilighted(kNoGrippyHilighted),
kCollapsedAtom(dont_AddRef( NS_NewAtom("collapsed"))),
kHiddenAtom(dont_AddRef( NS_NewAtom("hidden"))),
mDragListenerDelegate(nsnull)
{
// we start off vertical
mHorizontal = PR_FALSE;
}
//
// nsToolboxFrame dstr
//
// Cleanup, as necessary
//
nsToolboxFrame :: ~nsToolboxFrame ( )
{
if (mDragListenerDelegate) {
mDragListenerDelegate->NotifyFrameDestroyed();
NS_RELEASE(mDragListenerDelegate);
}
ClearGrippyList ( mGrippies );
}
//
// RefreshStyleContext
//
// Not exactly sure what this does ;)
//
void
nsToolboxFrame :: RefreshStyleContext(nsIPresContext* aPresContext,
nsIAtom * aNewContentPseudo,
nsCOMPtr<nsIStyleContext>* aCurrentStyle,
nsIContent * aContent,
nsIStyleContext* aParentStyle)
{
nsIStyleContext* newStyleContext;
aPresContext->ProbePseudoStyleContextFor(aContent,
aNewContentPseudo,
aParentStyle,
PR_FALSE,
&newStyleContext);
if (newStyleContext != aCurrentStyle->get())
*aCurrentStyle = dont_QueryInterface(newStyleContext);
} // RefreshStyleContext
NS_IMETHODIMP
nsToolboxFrame::GetAdditionalStyleContext(PRInt32 aIndex,
nsIStyleContext** aStyleContext) const
{
NS_PRECONDITION(nsnull != aStyleContext, "null OUT parameter pointer");
if (aIndex < 0) {
return NS_ERROR_INVALID_ARG;
}
*aStyleContext = nsnull;
switch (aIndex) {
case NS_TOOLBOX_GRIPPY_NORMAL_CONTEXT_INDEX:
*aStyleContext = mGrippyNormalStyle;
NS_IF_ADDREF(*aStyleContext);
break;
case NS_TOOLBOX_GRIPPY_ROLLOVER_CONTEXT_INDEX:
*aStyleContext = mGrippyRolloverStyle;
NS_IF_ADDREF(*aStyleContext);
break;
default:
return NS_ERROR_INVALID_ARG;
}
return NS_OK;
}
NS_IMETHODIMP
nsToolboxFrame::SetAdditionalStyleContext(PRInt32 aIndex,
nsIStyleContext* aStyleContext)
{
if (aIndex < 0) {
return NS_ERROR_INVALID_ARG;
}
switch (aIndex) {
case NS_TOOLBOX_GRIPPY_NORMAL_CONTEXT_INDEX:
mGrippyNormalStyle = aStyleContext;
break;
case NS_TOOLBOX_GRIPPY_ROLLOVER_CONTEXT_INDEX:
mGrippyRolloverStyle = aStyleContext;
break;
}
return NS_OK;
}
NS_IMETHODIMP
nsToolboxFrame::Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
UpdateStyles(&aPresContext);
// Register the delegate as a drag listener.
mDragListenerDelegate = new DragListenerDelegate(this);
if (! mDragListenerDelegate)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(mDragListenerDelegate);
nsCOMPtr<nsIContent> content;
rv = GetContent(getter_AddRefs(content));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMEventReceiver> reciever(do_QueryInterface(content));
reciever->AddEventListenerByIID(NS_STATIC_CAST(nsIDOMDragListener*, mDragListenerDelegate), nsIDOMDragListener::GetIID());
return rv;
}
void
nsToolboxFrame::UpdateStyles(nsIPresContext* aPresContext)
{
nsCOMPtr<nsIAtom> grippyRolloverPseudo ( dont_AddRef(NS_NewAtom(":toolbox-rollover")) );
RefreshStyleContext(aPresContext, grippyRolloverPseudo, &mGrippyRolloverStyle, mContent, mStyleContext);
nsCOMPtr<nsIAtom> grippyNormalPseudo ( dont_AddRef(NS_NewAtom(":toolbox-normal")) );
RefreshStyleContext(aPresContext, grippyNormalPseudo, &mGrippyNormalStyle, mContent, mStyleContext);
}
//
// Paint
//
// Paint our background and border like normal frames, but before we draw the
// children, draw our grippies for each toolbar.
//
NS_IMETHODIMP
nsToolboxFrame :: Paint ( nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)
{
// if we aren't visible then we are done.
const nsStyleDisplay* disp = (const nsStyleDisplay*)
mStyleContext->GetStyleData(eStyleStruct_Display);
if (!disp->mVisible)
return NS_OK;
// take care of bg painting, borders and children
nsresult retVal = nsBoxFrame::Paint ( aPresContext, aRenderingContext, aDirtyRect, aWhichLayer );
// now draw what makes us special
DrawGrippies ( aPresContext, aRenderingContext );
return retVal;
} // Paint
//
// DrawGrippies
//
// Redraws all the grippies in the toolbox by iterating over each toolbar in the DOM
// and figuring out how to draw the grippies based on size/visibility information
//
void
nsToolboxFrame :: DrawGrippies ( nsIPresContext& aPresContext, nsIRenderingContext & aRenderingContext ) const
{
for ( PRInt32 i = 0; i < mGrippies.Count(); ++i ) {
TabInfo* currGrippy = NS_STATIC_CAST(TabInfo*, mGrippies[i]);
PRBool hilight = (mGrippyHilighted == i) ? PR_TRUE : PR_FALSE;
DrawGrippy ( aPresContext, aRenderingContext, currGrippy->mBoundingRect, hilight );
} // for each child
} // DrawGrippies
//
// DrawGrippy
//
// Draw a single grippy in the given rectangle, either with or without rollover feedback.
//
void
nsToolboxFrame :: DrawGrippy ( nsIPresContext& aPresContext, nsIRenderingContext & aRenderingContext,
const nsRect & aBoundingRect, PRBool aDrawHilighted ) const
{
nsCOMPtr<nsIStyleContext> style ( aDrawHilighted ? mGrippyRolloverStyle : mGrippyNormalStyle ) ;
if ( !mGrippyRolloverStyle ) {
#ifdef NS_DEBUG
printf("nsToolboxFrame::DrawGrippy() -- style context null, css file not loaded correctly??\n");
#endif
return; // something must be seriously wrong
}
const nsStyleColor* grippyColor = (const nsStyleColor*)style->GetStyleData(eStyleStruct_Color);
const nsStyleSpacing* grippySpacing = (const nsStyleSpacing*)style->GetStyleData(eStyleStruct_Spacing);
// const nsStyleFont* grippyFont = (const nsStyleFont*)style->GetStyleData(eStyleStruct_Font);
nsToolboxFrame* nonConstSelf = NS_CONST_CAST(nsToolboxFrame*, this);
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, nonConstSelf,
aBoundingRect, aBoundingRect, *grippyColor, *grippySpacing, 0, 0);
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, nonConstSelf,
aBoundingRect, aBoundingRect, *grippySpacing, style, 0);
} // DrawGrippy
NS_IMETHODIMP
nsToolboxFrame::GetBoxInfo(nsIPresContext& aPresContext, const nsHTMLReflowState& aReflowState, nsBoxInfo& aSize)
{
CalculateGrippies(aPresContext);
return nsBoxFrame::GetBoxInfo(aPresContext, aReflowState, aSize);
}
NS_IMETHODIMP
nsToolboxFrame :: Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
nsresult errCode = nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
errCode = ReflowGrippies(aPresContext, aDesiredSize, aReflowState, aStatus);
return errCode;
} // Reflow
// After we have been flowed this should be flowed to place the grippies at there
// physical locations.
nsresult
nsToolboxFrame::ReflowGrippies(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
// get the rect we can place the grippies in. This is inside our borders and debug rect.
nsRect innerRect(0,0,0,0);
GetInnerRect(innerRect);
float p2t;
aPresContext.GetScaledPixelsToTwips(&p2t);
nscoord onePixel = NSIntPixelsToTwips(1, p2t);
nscoord grippyWidth = kGrippyWidthInPixels * onePixel; // remember to leave room for the grippy on the right
nscoord collapsedGrippyHeight = kCollapsedGrippyHeightInPixels * onePixel;
nsresult errCode = NS_OK;
const PRBool isHorz = IsHorizontal();
// iterate over all visible toolbar frames, moving the associated grippy
// next to the toolbar
mNumToolbars = 0;
nsIFrame* childFrame = mFrames.FirstChild();
while ( childFrame ) {
// get the childs rect and figure out the grippy size
nsCOMPtr<nsIContent> childContent;
childFrame->GetContent(getter_AddRefs(childContent));
nsRect grippyRect;
childFrame->GetRect(grippyRect);
if ( isHorz ) {
grippyRect.y = innerRect.y;
grippyRect.height = grippyWidth;
} else {
grippyRect.x = innerRect.x;
grippyRect.width = grippyWidth;
}
TabInfo *grippyInfo = FindGrippyForToolbar(mGrippies, childContent);
NS_ASSERTION(grippyInfo != 0, "Grippy Info Struct dissapeared!");
NS_ASSERTION(grippyInfo->mCollapsed == 0, "Collapsed toolbar has frame!");
// Set the location of the grippy to the left...
grippyInfo->SetBounds(grippyRect);
errCode = childFrame->GetNextSibling(&childFrame);
NS_ASSERTION(errCode == NS_OK, "failed to get next child");
mNumToolbars++;
}
// now move collapsed grippies to the bottom
for ( PRInt32 i = 0; i < mGrippies.Count(); ++i ) {
TabInfo* currGrippy = NS_STATIC_CAST(TabInfo*, mGrippies[i]);
if (currGrippy->mCollapsed) {
// remember we are just inverting the coord system here so in a
// horzontal toolbox our height is our width. Thats why we just use
// height here on both x and y coords.
if ( isHorz )
currGrippy->mBoundingRect.x = aDesiredSize.width - collapsedGrippyHeight;
else
currGrippy->mBoundingRect.y = aDesiredSize.height - collapsedGrippyHeight;
}
}
return errCode;
}
// called to figure out how big our grippies are and how many we have
// this will be called by boxes reflow method.
void
nsToolboxFrame::CalculateGrippies(nsIPresContext& aPresContext)
{
// compute amount (in twips) each toolbar will be offset from the right because of
// the grippy
float p2t;
aPresContext.GetScaledPixelsToTwips(&p2t);
nscoord onePixel = NSIntPixelsToTwips(1, p2t);
nscoord collapsedGrippyHeight = kCollapsedGrippyHeightInPixels * onePixel;
nscoord collapsedGrippyWidth = kCollapsedGrippyWidthInPixels * onePixel;
const PRBool isHorz = IsHorizontal();
{
nscoord grippyWidth = kGrippyWidthInPixels * onePixel; // remember to leave room for the grippy on the right
// Leave room at the side for the grippies of visible toolbars. Make a margin
// of the appropriate dimensions.
mInset = nsMargin(0,0,0,0);
if ( isHorz ) // Set margins so we have a place for uncollapsed grippies
mInset.top = grippyWidth;
else
mInset.left = grippyWidth;
}
// Save old tabs so we can make newly collapsed bars as wide as they WERE tall. We will
// release the grippies in mGrippies at the very end when we dispose of |oldGrippies|
nsVoidArray oldGrippies, emptyList;
oldGrippies = mGrippies;
mGrippies = emptyList;
// ----- Calculate a new set of grippy states...
// iterate over each content node to see if we can find one with the "collapsed"
// attribute set. If so, we have a collapsed toolbar.
nsAutoString value;
int numCollapsedGrippies = 0;
nscoord grippyPos = 0;
// Get the first child of the toolbox content node
unsigned int contentCounter = 0;
nsCOMPtr<nsIContent> childContent;
nsresult errCode = mContent->ChildAt(contentCounter, *getter_AddRefs(childContent));
NS_ASSERTION(errCode == NS_OK,"failed to get first child");
// iterate over each content node to see if we can find one with the "collapsed"
// attribute set. If so, we have a collapsed toolbar.
while ( childContent ) {
// is this bar collapsed?
value = "";
childContent->GetAttribute(kNameSpaceID_None, kCollapsedAtom, value);
if (value == "true") { // The bar is collapsed!
nscoord grippyWidth;
nscoord grippyHeight;
if ( isHorz ) {
grippyWidth = collapsedGrippyHeight;
grippyHeight = collapsedGrippyWidth;
} else {
grippyWidth = collapsedGrippyWidth;
grippyHeight = collapsedGrippyHeight;
}
TabInfo* oldGrippy = FindGrippyForToolbar ( oldGrippies, childContent );
if ( oldGrippy ) { // Inherit the old size...
if ( isHorz ) { // If laying out children horizontally...
if ( oldGrippy->mCollapsed) // Did it used to be collapsed?
grippyHeight = oldGrippy->mBoundingRect.height; // Copy old width
else
grippyHeight = oldGrippy->mBoundingRect.width; // Else copy old height
} else { // If laying out children vertically...
if ( oldGrippy->mCollapsed ) // Did it used to be collapsed?
grippyWidth = oldGrippy->mBoundingRect.width; // Copy old width
else
grippyWidth = oldGrippy->mBoundingRect.height; // Else copy old height
}
}
if ( isHorz ) {
mGrippies.AppendElement( new TabInfo(childContent, PR_TRUE,
nsRect(0, grippyPos, grippyWidth, grippyHeight)) );
grippyPos += grippyHeight;
} else {
mGrippies.AppendElement( new TabInfo(childContent, PR_TRUE,
nsRect(grippyPos, 0, grippyWidth, grippyHeight)) );
grippyPos += grippyWidth;
}
++numCollapsedGrippies;
} else { // The bar is NOT collapsed!!
mGrippies.AppendElement( new TabInfo(childContent, PR_FALSE) );
}
// next!
++contentCounter;
errCode = mContent->ChildAt(contentCounter, *getter_AddRefs(childContent));
NS_ASSERTION(errCode == NS_OK,"failed to get next child");
}
// if there are any collapsed bars, we need to leave room at the bottom of
// the box for the grippies. Adjust the margins before we reflow the box.
if ( numCollapsedGrippies ) {
if ( isHorz )
mInset.left = collapsedGrippyHeight;
else
mInset.bottom = collapsedGrippyHeight;
}
// make sure we now dispose of the old grippies since we have allocated
// new ones.
ClearGrippyList ( oldGrippies );
}
//
// FindGrippyForToolbar
//
// Utility routine to scan through the grippy list looking for one in the list
// associated with the given content object (which is the toolbar's content object).
//
// Will return nsnull if it cannot find the toolbar.
//
nsToolboxFrame::TabInfo*
nsToolboxFrame :: FindGrippyForToolbar ( nsVoidArray & inList, const nsIContent* inContent ) const
{
for ( PRInt32 i = 0; i < inList.Count(); ++i ) {
TabInfo* currGrippy = NS_STATIC_CAST(TabInfo*, inList[i]);
if ( currGrippy->mToolbar == inContent )
return currGrippy;
}
return nsnull;
} // FindGrippyForToolbar
//
// ClearGrippyList
//
// Since we are assuming the array "owns" the grippies once they go in there,
// we need to make sure that when the list goes away that they are cleaned up. The
// nsVoidArray does not know how to do this, so we need to do it ourselves.
//
void
nsToolboxFrame :: ClearGrippyList ( nsVoidArray & inList )
{
for ( PRInt32 i = 0; i < inList.Count(); ++i ) {
TabInfo* currGrippy = NS_STATIC_CAST(TabInfo*, inList[i]);
delete currGrippy;
}
} // ClearGrippyList
//
// GetInset
//
// Our Reflow() method computes a margin for the grippies and for collased grippies (if
// any). Return this pre-computed margin when asked by the box.
//
void
nsToolboxFrame::GetInset(nsMargin& margin)
{
margin = mInset;
}
//
// GetFrameForPoint
//
// Override to process events in our own frame
//
NS_IMETHODIMP
nsToolboxFrame :: GetFrameForPoint(nsIPresContext* aPresContext,
const nsPoint& aPoint,
nsIFrame** aFrame)
{
nsresult retVal = nsHTMLContainerFrame::GetFrameForPoint(aPresContext, aPoint, aFrame);
// returning NS_OK means that we tell the frame finding code that we have something
// and to stop looking elsewhere for a frame.
if ( aFrame && *aFrame == this )
retVal = NS_OK;
else if ( retVal != NS_OK ) {
*aFrame = this;
retVal = NS_OK;
}
return retVal;
} // GetFrameForPoint
//
// HandleEvent
//
//
NS_IMETHODIMP
nsToolboxFrame :: HandleEvent ( nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
if ( !aEvent )
return nsEventStatus_eIgnore;
switch ( aEvent->message ) {
case NS_MOUSE_LEFT_CLICK:
// BUG 3752 aEvent->point is invalid here.
break;
case NS_MOUSE_LEFT_BUTTON_UP:
OnMouseLeftClick ( &aPresContext, aEvent->point );
break;
case NS_MOUSE_MOVE:
OnMouseMove ( &aPresContext, aEvent->point );
break;
case NS_MOUSE_EXIT:
OnMouseExit ( &aPresContext);
break;
default:
break;
} // case of which event
return nsEventStatus_eIgnore;
} // HandleEvent
//
// ConvertToLocalPoint
//
// Given a point in the coordinate system of the parent view, convert to a point in the
// frame's local coordinate system.
//
void
nsToolboxFrame :: ConvertToLocalPoint ( nsIPresContext* aPresContext, nsPoint & ioPoint )
{
nsIView* view = nsnull; // note: |view| not AddRef'd
nsPoint offset;
if ( GetOffsetFromView(aPresContext, offset, &view) == NS_OK )
ioPoint -= offset;
} // ConvertToLocalPoint
//
// OnMouseMove
//
// Handle mouse move events for hilighting and unhilighting the grippies. |aMouseLoc|
// is not in local frame coordinates.
//
void
nsToolboxFrame :: OnMouseMove ( nsIPresContext* aPresContext, nsPoint & aMouseLoc )
{
nsPoint localMouseLoc = aMouseLoc;
ConvertToLocalPoint ( aPresContext, localMouseLoc );
for ( int i = 0; i < mGrippies.Count(); ++i ) {
TabInfo* currGrippy = NS_STATIC_CAST(TabInfo*, mGrippies[i]);
if ( currGrippy->mBoundingRect.Contains(localMouseLoc) ) {
if ( i != mGrippyHilighted ) {
// unhilight the old one
if ( mGrippyHilighted != kNoGrippyHilighted ) {
TabInfo* hilightedGrippy = NS_STATIC_CAST(TabInfo*, mGrippies[mGrippyHilighted]);
Invalidate ( aPresContext, hilightedGrippy->mBoundingRect, PR_FALSE );
}
// hilight the new one and remember it
mGrippyHilighted = i;
Invalidate ( aPresContext, currGrippy->mBoundingRect, PR_FALSE );
} // if in a new tab
}
} // for each toolbar
} // OnMouseMove
//
// OnMouseLeftClick
//
// Check if a click is in a grippy and expand/collapse appropriately. |aMouseLoc|
// is not in local frame coordinates.
//
void
nsToolboxFrame :: OnMouseLeftClick ( nsIPresContext* aPresContext, nsPoint & aMouseLoc )
{
nsPoint localMouseLoc = aMouseLoc;
ConvertToLocalPoint ( aPresContext, localMouseLoc );
for ( int i = 0; i < mGrippies.Count(); ++i ) {
TabInfo* currGrippy = NS_STATIC_CAST(TabInfo*, mGrippies[i]);
if ( currGrippy->mBoundingRect.Contains(localMouseLoc) ) {
if ( currGrippy->mCollapsed )
ExpandToolbar ( *currGrippy );
else
CollapseToolbar ( *currGrippy );
// don't keep repeating this process since toolbars have now be
// relaid out and a new toolbar may be under the current mouse
// location!
break;
}
}
} // OnMouseLeftClick
//
// OnMouseExit
//
// Update the grippies that may have been hilighted while the mouse was within the
// manager.
//
void
nsToolboxFrame :: OnMouseExit (nsIPresContext* aPresContext)
{
if ( mGrippyHilighted != kNoGrippyHilighted ) {
TabInfo* hilightedGrippy = NS_STATIC_CAST(TabInfo*, mGrippies[mGrippyHilighted]);
Invalidate ( aPresContext, hilightedGrippy->mBoundingRect, PR_FALSE );
mGrippyHilighted = kNoGrippyHilighted;
}
} // OnMouseExit
//
// CollapseToolbar
//
// Given the tab that was clicked on, collapse its corresponding toolbar. This
// assumes that the tab is expanded.
//
void
nsToolboxFrame :: CollapseToolbar ( TabInfo & inTab )
{
if ( inTab.mToolbar ) {
#ifdef NS_DEBUG
printf("CollapseToolbar:: collapsing\n");
#endif
nsresult errCode = inTab.mToolbar->SetAttribute ( kNameSpaceID_None, kCollapsedAtom, "true", PR_TRUE );
#ifdef NS_DEBUG
if ( errCode )
printf("Problem setting collapsed attribute while collapsing toolbar\n");
#endif
}
} // CollapseToolbar
//
// ExpandToolbar
//
// Given the collapsed (horizontal) tab that was clicked on, expand its
// corresponding toolbar. This assumes the tab is collapsed.
//
void
nsToolboxFrame :: ExpandToolbar ( TabInfo & inTab )
{
// nsresult errCode = mContent->UnsetAttribute ( kNameSpaceID_None, kCollapsedAtom, PR_TRUE );
nsresult errCode = inTab.mToolbar->SetAttribute ( kNameSpaceID_None, kCollapsedAtom, "false", PR_TRUE );
#ifdef NS_DEBUG
if ( errCode )
printf("Problem clearing collapsed attribute while expanding toolbar\n");
#endif
} // ExpandToolbar
////////////////////////////////////////////////////////////////////////
nsresult
nsToolboxFrame::HandleEvent(nsIDOMEvent* aEvent)
{
//printf("nsToolbarDragListener::HandleEvent\n");
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
nsresult
nsToolboxFrame::DragEnter(nsIDOMEvent* aDragEvent)
{
nsIDragService* dragService;
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
nsIDragService::GetIID(),
(nsISupports **)&dragService);
if ( NS_SUCCEEDED(rv) ) {
nsCOMPtr<nsIDragSession> dragSession(do_QueryInterface(dragService));
if ( dragSession ) {
PRBool flavorSupported = PR_FALSE;
dragSession->IsDataFlavorSupported(TOOLBAR_MIME, &flavorSupported);
if ( flavorSupported ) {
dragSession->SetCanDrop(PR_TRUE);
rv = NS_ERROR_BASE; // consume event
}
}
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
} else {
rv = NS_OK;
}
return rv;
}
////////////////////////////////////////////////////////////////////////
nsresult
nsToolboxFrame::DragOver(nsIDOMEvent* aDragEvent)
{
// now tell the drag session whether we can drop here
nsIDragService* dragService;
nsresult rv = nsServiceManager::GetService(kCDragServiceCID, nsIDragService::GetIID(),
(nsISupports **)&dragService);
if ( NS_SUCCEEDED(rv) ) {
nsCOMPtr<nsIDragSession> dragSession(do_QueryInterface(dragService));
if ( dragSession ) {
PRBool flavorSupported = PR_FALSE;
dragSession->IsDataFlavorSupported(TOOLBAR_MIME, &flavorSupported);
if ( flavorSupported ) {
// Right here you need to figure out where the mouse is
// and whether you can drop here
dragSession->SetCanDrop(PR_TRUE);
rv = NS_ERROR_BASE; // consume event
}
}
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
}
// NS_OK means event is NOT consumed
return rv;
}
////////////////////////////////////////////////////////////////////////
nsresult
nsToolboxFrame::DragExit(nsIDOMEvent* aDragEvent)
{
return NS_ERROR_BASE; // consumes event
}
////////////////////////////////////////////////////////////////////////
nsresult
nsToolboxFrame::DragDrop(nsIDOMEvent* aMouseEvent)
{
// Create drag service for getting state of drag
nsIDragService* dragService;
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
nsIDragService::GetIID(),
(nsISupports **)&dragService);
if (NS_OK == rv) {
nsCOMPtr<nsIDragSession> dragSession(do_QueryInterface(dragService));
if (dragSession) {
// Create transferable for getting the drag data
nsCOMPtr<nsITransferable> trans;
rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
nsITransferable::GetIID(),
(void**) getter_AddRefs(trans));
if ( NS_SUCCEEDED(rv) && trans ) {
// Add the toolbar Flavor to the transferable, because that is the only type of data we are
// looking for at the moment.
trans->AddDataFlavor(TOOLBAR_MIME);
// Fill the transferable with data for each drag item in succession
PRUint32 numItems = 0;
if (NS_SUCCEEDED(dragSession->GetNumDropItems(&numItems))) {
//printf("Num Drop Items %d\n", numItems);
PRUint32 i;
for (i=0;i<numItems;++i) {
if (NS_SUCCEEDED(dragSession->GetData(trans, i))) {
// Get the string data out of the transferable as a nsISupportsString.
nsCOMPtr<nsISupports> data;
PRUint32 len;
char* whichFlavor = nsnull;
trans->GetAnyTransferData(&whichFlavor, getter_AddRefs(data), &len);
nsCOMPtr<nsISupportsString> dataAsString ( do_QueryInterface(data) );
// If the string was not empty then make it so.
if ( dataAsString ) {
char* stuffToPaste;
dataAsString->ToString ( &stuffToPaste );
printf("Dropped: %s\n", stuffToPaste);
dragSession->SetCanDrop(PR_TRUE);
}
nsAllocator::Free ( whichFlavor );
}
} // foreach drag item
}
} // if valid transferable
} // if valid drag session
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
} // if valid drag service
return NS_ERROR_BASE; // consume the event;
}

View File

@@ -1,226 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
//
// Mike Pinkerton
// Netscape Communications
//
// nsToolboxFrame is a layout object that contains one or more toolbar frames
// (specified as children in the DOM). These toolbars are laid out one on top
// of the other, and can be of varying heights but are all of the same width
// (the full width of the toolbox). Each toolbar is associated with a "grippy"
// which can be used to either collapse a particular toolbar or as a handle to
// pick up and move a toolbar to a new position within the toolbox. When toolbars
// are collapsed, it's grippy is moved to the bottom of the box and laid on
// its side. Clicking again on the grippy will reinstate the toolbar to its previous
// position in the toolbox.
//
// As mentioned above, the toolbox expects its toolbars to be its children in
// the DOM. The exact structure of the children is documented on:
// http://www.mozilla.org/xpfe/DMWSpecNew.html
//
#ifndef nsToolBoxFrame_h___
#define nsToolBoxFrame_h___
#include "nsIDOMDragListener.h"
#include "nsHTMLContainerFrame.h"
#include "nsIStyleContext.h"
#include "nsIContent.h"
#include "nsXULAtoms.h"
#include "nsCOMPtr.h"
#include "nsBoxFrame.h"
#define NS_TOOLBOX_GRIPPY_NORMAL_CONTEXT_INDEX 0
#define NS_TOOLBOX_GRIPPY_ROLLOVER_CONTEXT_INDEX 1
class nsToolboxFrame : public nsBoxFrame
{
public:
friend nsresult NS_NewToolboxFrame(nsIFrame** aNewFrame);
// nsIHTMLReflow overrides
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD GetBoxInfo(nsIPresContext& aPresContext, const nsHTMLReflowState& aReflowState, nsBoxInfo& aSize);
NS_IMETHOD Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow);
NS_IMETHOD GetAdditionalStyleContext(PRInt32 aIndex,
nsIStyleContext** aStyleContext) const;
NS_IMETHOD SetAdditionalStyleContext(PRInt32 aIndex,
nsIStyleContext* aStyleContext);
// Overridden to capture events
NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext,
const nsPoint& aPoint,
nsIFrame** aFrame);
/*BEGIN implementations of dragevent handler interface*/
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
virtual nsresult DragEnter(nsIDOMEvent* aDragEvent);
virtual nsresult DragOver(nsIDOMEvent* aDragEvent);
virtual nsresult DragExit(nsIDOMEvent* aDragEvent);
virtual nsresult DragDrop(nsIDOMEvent* aDragEvent);
virtual nsresult DragGesture(nsIDOMEvent* aDragEvent) { return NS_OK; }
/*END implementations of dragevent handler interface*/
protected:
enum { kGrippyWidthInPixels = 10, kCollapsedGrippyHeightInPixels = 10, kCollapsedGrippyWidthInPixels = 50 } ;
enum { kNoGrippyHilighted = -1 } ;
struct TabInfo {
TabInfo( nsIContent * inContent, PRBool inCollapsed,
const nsRect &inBounds = nsRect(0,0,0,0))
: mToolbar(inContent),
mBoundingRect(inBounds),
mCollapsed(inCollapsed)
{
}
void SetBounds(const nsRect &inBounds) { mBoundingRect = inBounds; }
nsIContent* mToolbar; // content object associated w/ toolbar frame. We don't own it.
nsRect mBoundingRect;
PRBool mCollapsed;
};
nsToolboxFrame();
virtual ~nsToolboxFrame();
virtual void UpdateStyles(nsIPresContext* aPresContext);
virtual void CalculateGrippies(nsIPresContext& aPresContext);
virtual nsresult ReflowGrippies(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
void RefreshStyleContext(nsIPresContext* aPresContext,
nsIAtom * aNewContentPseudo,
nsCOMPtr<nsIStyleContext>* aCurrentStyle,
nsIContent * aContent,
nsIStyleContext* aParentStyle) ;
void DrawGrippies ( nsIPresContext& aPresContext, nsIRenderingContext & aContext ) const ;
void DrawGrippy ( nsIPresContext& aPresContext, nsIRenderingContext & aContext,
const nsRect & aBoundingRect, PRBool aDrawHilighted ) const ;
void CollapseToolbar ( TabInfo & inTab ) ;
void ExpandToolbar ( TabInfo & inTab ) ;
void ConvertToLocalPoint ( nsIPresContext* aPresContext, nsPoint & ioPoint ) ;
void OnMouseMove ( nsIPresContext* aPresContext, nsPoint & aMouseLoc ) ;
void OnMouseExit ( nsIPresContext* aPresContext ) ;
void OnMouseLeftClick ( nsIPresContext* aPresContext, nsPoint & aMouseLoc ) ;
// utility routines
TabInfo* FindGrippyForToolbar ( nsVoidArray & inList, const nsIContent* inContent ) const ;
void ClearGrippyList ( nsVoidArray & inList ) ;
// style context for the normal state and rollover state of grippies
nsCOMPtr<nsIStyleContext> mGrippyNormalStyle;
nsCOMPtr<nsIStyleContext> mGrippyRolloverStyle;
nsMargin mInset;
virtual void GetInset(nsMargin& margin);
unsigned long mSumOfToolbarHeights;
nsVoidArray mGrippies; // list of all active grippies
unsigned short mNumToolbars;
short mGrippyHilighted; // used to indicate which grippy the mouse is inside
const nsCOMPtr<nsIAtom> kCollapsedAtom ;
const nsCOMPtr<nsIAtom> kHiddenAtom ;
class DragListenerDelegate : public nsIDOMDragListener
{
protected:
nsToolboxFrame* mFrame;
public:
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIDOMEventListener interface
virtual nsresult HandleEvent(nsIDOMEvent* aEvent)
{
return mFrame ? mFrame->HandleEvent(aEvent) : NS_OK;
}
virtual nsresult DragGesture(nsIDOMEvent* aEvent)
{
return mFrame ? mFrame->DragGesture(aEvent) : NS_OK;
}
// nsIDOMDragListener interface
virtual nsresult DragEnter(nsIDOMEvent* aMouseEvent)
{
return mFrame ? mFrame->DragEnter(aMouseEvent) : NS_OK;
}
virtual nsresult DragOver(nsIDOMEvent* aMouseEvent)
{
return mFrame ? mFrame->DragOver(aMouseEvent) : NS_OK;
}
virtual nsresult DragExit(nsIDOMEvent* aMouseEvent)
{
return mFrame ? mFrame->DragExit(aMouseEvent) : NS_OK;
}
virtual nsresult DragDrop(nsIDOMEvent* aMouseEvent)
{
return mFrame ? mFrame->DragDrop(aMouseEvent) : NS_OK;
}
// Implementation methods
DragListenerDelegate(nsToolboxFrame* aFrame) : mFrame(aFrame)
{
NS_INIT_REFCNT();
}
virtual ~DragListenerDelegate() {}
void NotifyFrameDestroyed() { mFrame = nsnull; }
};
DragListenerDelegate* mDragListenerDelegate;
// pass-by-value not allowed for a toolbox because it corresponds 1-to-1
// with an element in the UI.
nsToolboxFrame ( const nsToolboxFrame& aFrame ) ; // DO NOT IMPLEMENT
nsToolboxFrame& operator= ( const nsToolboxFrame& aFrame ) ; // DO NOT IMPLEMENT
}; // class nsToolboxFrame
#endif

View File

@@ -1,458 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsIDOMElement.h"
#include "nsINameSpaceManager.h"
#include "nsHTMLAtoms.h"
#include "nsTreeCellFrame.h"
#include "nsTreeFrame.h"
#include "nsTreeRowFrame.h"
#include "nsIStyleContext.h"
#include "nsIPresContext.h"
#include "nsIPresShell.h"
#include "nsIContent.h"
#include "nsIDocument.h"
#include "nsIStyleSet.h"
#include "nsIViewManager.h"
#include "nsCSSRendering.h"
#include "nsXULAtoms.h"
#include "nsCOMPtr.h"
#include "nsINameSpaceManager.h"
//
// NS_NewTreeCellFrame
//
// Creates a new tree cell frame
//
nsresult
NS_NewTreeCellFrame (nsIFrame** aNewFrame)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsTreeCellFrame* theFrame = new nsTreeCellFrame();
if (theFrame == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = theFrame;
return NS_OK;
} // NS_NewTreeCellFrame
// Constructor
nsTreeCellFrame::nsTreeCellFrame()
:nsTableCellFrame() { mAllowEvents = PR_FALSE; mIsHeader = PR_FALSE; mAnonymousContent = nsnull; }
// Destructor
nsTreeCellFrame::~nsTreeCellFrame()
{
}
NS_IMETHODIMP
nsTreeCellFrame::Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsTableCellFrame::Init(aPresContext, aContent, aParent, aContext,
aPrevInFlow);
// Figure out if we allow events.
nsAutoString attrValue;
nsresult result = aContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::allowevents, attrValue);
attrValue.ToLowerCase();
PRBool allowEvents = (result == NS_CONTENT_ATTR_NO_VALUE ||
(result == NS_CONTENT_ATTR_HAS_VALUE && attrValue=="true"));
SetAllowEvents(allowEvents);
// Determine if we're a column header or not.
// Get row group frame
nsIFrame* rowGroupFrame = nsnull;
aParent->GetParent(&rowGroupFrame);
if (rowGroupFrame != nsnull)
{
// Get the display type of the row group frame and see if it's a header or body
nsCOMPtr<nsIStyleContext> parentContext;
rowGroupFrame->GetStyleContext(getter_AddRefs(parentContext));
if (parentContext)
{
const nsStyleDisplay* display = (const nsStyleDisplay*)
parentContext->GetStyleData(eStyleStruct_Display);
if (display->mDisplay == NS_STYLE_DISPLAY_TABLE_HEADER_GROUP)
{
mIsHeader = PR_TRUE;
}
else mIsHeader = PR_FALSE;
// Get the table frame.
nsTableFrame* tableFrame = nsnull;
rv = nsTableFrame::GetTableFrame(rowGroupFrame, tableFrame);
if (NS_FAILED(rv) || (nsnull == tableFrame)) {
return rv;
}
mTreeFrame = (nsTreeFrame*)tableFrame;
}
}
return rv;
}
NS_IMETHODIMP nsTreeCellFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint)
{
nsresult rv = nsTableCellFrame::AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aHint);
if (mAnonymousContent && (aAttribute == nsHTMLAtoms::align || aAttribute == nsXULAtoms::crop
|| aAttribute == nsHTMLAtoms::value))
{
nsAutoString value;
// XXX should check if attribute has been removed
mContent->GetAttribute(kNameSpaceID_None, aAttribute, value);
mAnonymousContent->SetAttribute(kNameSpaceID_None, aAttribute, value, PR_TRUE);
}
return rv;
}
nsTableFrame* nsTreeCellFrame::GetTreeFrame()
{
return mTreeFrame;
}
NS_METHOD nsTreeCellFrame::Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
nsresult rv = nsTableCellFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
return rv;
}
NS_IMETHODIMP
nsTreeCellFrame::GetFrameForPoint(nsIPresContext* aPresContext,
const nsPoint& aPoint,
nsIFrame** aFrame)
{
if (mAllowEvents)
{
return nsTableCellFrame::GetFrameForPoint(aPresContext, aPoint, aFrame);
}
else
{
nsresult result = nsTableCellFrame::GetFrameForPoint(aPresContext, aPoint, aFrame);
nsCOMPtr<nsIContent> content;
if (*aFrame) {
(*aFrame)->GetContent(getter_AddRefs(content));
if (content) {
// This allows selective overriding for subcontent.
nsAutoString value;
content->GetAttribute(kNameSpaceID_None, nsXULAtoms::allowevents, value);
if (value == "true")
return result;
}
}
*aFrame = this; // Capture all events so that we can perform selection and expand/collapse.
return NS_OK;
}
}
NS_IMETHODIMP
nsTreeCellFrame::HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
aEventStatus = nsEventStatus_eConsumeDoDefault;
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) {
if (((nsMouseEvent*)aEvent)->clickCount == 2)
HandleDoubleClickEvent(aPresContext, aEvent, aEventStatus);
else
HandleMouseDownEvent(aPresContext, aEvent, aEventStatus);
}
else if (aEvent->message == NS_MOUSE_ENTER)
HandleMouseEnterEvent(aPresContext, aEvent, aEventStatus);
else if (aEvent->message == NS_MOUSE_EXIT)
HandleMouseExitEvent(aPresContext, aEvent, aEventStatus);
else if (aEvent->message == NS_MOUSE_LEFT_DOUBLECLICK)
HandleDoubleClickEvent(aPresContext, aEvent, aEventStatus);
return NS_OK;
}
nsresult
nsTreeCellFrame::HandleMouseDownEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
if (mIsHeader) {
nsTableColFrame* leftFlex = nsnull;
nsPoint point = ((nsMouseEvent*)aEvent)->point;
if (CanResize(point, &leftFlex))
{
// Begin capturing events.
nsIFrame* frame;
GetParent(&frame);
nsTreeRowFrame* treeRow = (nsTreeRowFrame*)frame;
treeRow->HeaderDrag(&aPresContext, PR_TRUE);
// Inform the tree row of the flexing column
treeRow->SetFlexingColumn(leftFlex);
nsRect rect;
GetRect(rect);
treeRow->SetHeaderPosition(point.x);
}
}
else
{
// Perform a selection
if (((nsMouseEvent *)aEvent)->isShift)
mTreeFrame->RangedSelection(aPresContext, this); // Applying a ranged selection.
#ifdef XP_MAC
else if (((nsMouseEvent *)aEvent)->isMeta)
mTreeFrame->ToggleSelection(aPresContext, this);
#else
else if (((nsMouseEvent *)aEvent)->isControl)
mTreeFrame->ToggleSelection(aPresContext, this); // Applying a toggle selection.
#endif
else mTreeFrame->SetSelection(aPresContext, this); // Doing a single selection only.
}
return NS_OK;
}
nsresult
nsTreeCellFrame::HandleMouseEnterEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
if (mIsHeader)
{
// Nothing to do?
}
else
{
// Set our hover to true
Hover(aPresContext, PR_TRUE);
}
return NS_OK;
}
nsresult
nsTreeCellFrame::HandleMouseExitEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
if (mIsHeader)
{
}
else
{
// Set our hover to false
Hover(aPresContext, PR_FALSE);
}
return NS_OK;
}
PRBool
nsTreeCellFrame::CanResize(nsPoint& aPoint, nsTableColFrame** aResult) {
nsRect rect;
GetRect(rect);
PRInt32 diff = (rect.x + rect.width) - aPoint.x;
nsCOMPtr<nsIContent> parent;
mContent->GetParent(*getter_AddRefs(parent));
PRInt32 index;
parent->IndexOf(mContent, index);
PRInt32 count;
parent->ChildCount(count);
PRBool onLeftEdge = (index > 0 && (rect.width - diff) <= 90);
PRBool onRightEdge = (index < (count-1) && diff <= 90);
if (onLeftEdge || onRightEdge) {
// We're over the right place.
// Ensure that we have flexible columns to the left and to the right.
nsTableFrame* tableFrame = nsnull;
nsTableFrame::GetTableFrame(this, tableFrame);
nsTreeFrame* treeFrame = (nsTreeFrame*)tableFrame;
if (onLeftEdge)
index--;
return (treeFrame->ContainsFlexibleColumn(0, index, aResult) &&
treeFrame->ContainsFlexibleColumn(index+1, count-1, nsnull));
}
return PR_FALSE;
}
NS_IMETHODIMP
nsTreeCellFrame::GetCursor(nsIPresContext& aPresContext,
nsPoint& aPoint,
PRInt32& aCursor)
{
if (mIsHeader) {
// Figure out if the point is over the resize stuff.
nsTableColFrame* dummy = nsnull;
if (CanResize(aPoint, &dummy)) {
aCursor = NS_STYLE_CURSOR_W_RESIZE;
}
else {
aCursor = NS_STYLE_CURSOR_DEFAULT;
}
}
else aCursor = NS_STYLE_CURSOR_DEFAULT;
return NS_OK;
}
void
nsTreeCellFrame::ToggleOpenClose()
{
if (!mIsHeader)
{
// Perform an expand/collapse
// Iterate up the chain to the row and then to the item.
nsCOMPtr<nsIContent> treeItemContent;
nsCOMPtr<nsIContent> treeRowContent;
mContent->GetParent(*getter_AddRefs(treeRowContent));
treeRowContent->GetParent(*getter_AddRefs(treeItemContent));
nsCOMPtr<nsIDOMElement> treeItem( do_QueryInterface(treeItemContent) );
NS_ASSERTION(treeItem, "not a DOM element");
if (! treeItem)
return;
// Take the tree item content and toggle the value of its open attribute.
nsAutoString attrValue;
treeItem->GetAttribute("open", attrValue);
attrValue.ToLowerCase();
PRBool isExpanded = (attrValue=="true");
if (isExpanded)
{
// We're collapsing and need to remove frames from the flow.
treeItem->RemoveAttribute("open");
}
else
{
// We're expanding and need to add frames to the flow.
treeItem->SetAttribute("open", "true");
}
}
}
void
nsTreeCellFrame::Open()
{
if (!mIsHeader)
{
// Perform an expand/collapse
// Iterate up the chain to the row and then to the item.
nsCOMPtr<nsIContent> treeItemContent;
nsCOMPtr<nsIContent> treeRowContent;
mContent->GetParent(*getter_AddRefs(treeRowContent));
treeRowContent->GetParent(*getter_AddRefs(treeItemContent));
nsCOMPtr<nsIDOMElement> treeItem( do_QueryInterface(treeItemContent) );
NS_ASSERTION(treeItem, "not a DOM element");
if (! treeItem)
return;
// Take the tree item content and toggle the value of its open attribute.
nsAutoString attrValue;
treeItem->GetAttribute("open", attrValue);
attrValue.ToLowerCase();
PRBool isExpanded = (attrValue=="true");
if (!isExpanded) {
// We're expanding and need to add frames to the flow.
treeItem->SetAttribute("open", "true");
}
}
}
void
nsTreeCellFrame::Close()
{
if (!mIsHeader)
{
// Perform an expand/collapse
// Iterate up the chain to the row and then to the item.
nsCOMPtr<nsIContent> treeItemContent;
nsCOMPtr<nsIContent> treeRowContent;
mContent->GetParent(*getter_AddRefs(treeRowContent));
treeRowContent->GetParent(*getter_AddRefs(treeItemContent));
nsCOMPtr<nsIDOMElement> treeItem( do_QueryInterface(treeItemContent) );
NS_ASSERTION(treeItem, "not a DOM element");
if (! treeItem)
return;
// Take the tree item content and toggle the value of its open attribute.
nsAutoString attrValue;
treeItem->GetAttribute("open", attrValue);
attrValue.ToLowerCase();
PRBool isExpanded = (attrValue=="true");
if (isExpanded) {
// We're expanding and need to add frames to the flow.
treeItem->RemoveAttribute("open");
}
}
}
nsresult
nsTreeCellFrame::HandleDoubleClickEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
ToggleOpenClose();
return NS_OK;
}
void nsTreeCellFrame::Hover(nsIPresContext& aPresContext, PRBool isHover, PRBool notifyForReflow)
{
nsCOMPtr<nsIAtom> kHoverAtom(dont_AddRef(NS_NewAtom("hover")));
nsCOMPtr<nsIContent> rowContent;
nsCOMPtr<nsIContent> itemContent;
mContent->GetParent(*getter_AddRefs(rowContent));
rowContent->GetParent(*getter_AddRefs(itemContent));
if (isHover)
{
// We're selecting the node.
mContent->SetAttribute(kNameSpaceID_None, kHoverAtom, "true", notifyForReflow);
rowContent->SetAttribute(kNameSpaceID_None, kHoverAtom, "true", notifyForReflow);
itemContent->SetAttribute(kNameSpaceID_None, kHoverAtom, "true", notifyForReflow);
}
else
{
// We're deselecting the node.
mContent->UnsetAttribute(kNameSpaceID_None, kHoverAtom, notifyForReflow);
rowContent->UnsetAttribute(kNameSpaceID_None, kHoverAtom, notifyForReflow);
itemContent->UnsetAttribute(kNameSpaceID_None, kHoverAtom, notifyForReflow);
}
}
NS_IMETHODIMP
nsTreeCellFrame::Destroy(nsIPresContext& aPresContext)
{
return nsTableCellFrame::Destroy(aPresContext);
}

View File

@@ -1,100 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsTableCellFrame.h"
class nsTableColFrame;
class nsTreeFrame;
class nsTreeCellFrame : public nsTableCellFrame
{
public:
friend nsresult NS_NewTreeCellFrame(nsIFrame** aNewFrame);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint);
NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext,
const nsPoint& aPoint, // Overridden to capture events
nsIFrame** aFrame);
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow); // Overridden to set whether we're a column header
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD Destroy(nsIPresContext& aPresContext);
NS_IMETHOD GetCursor(nsIPresContext& aPresContext,
nsPoint& aPoint,
PRInt32& aCursor);
void Hover(nsIPresContext& presContext, PRBool isHover, PRBool notifyForReflow = PR_TRUE);
nsTableFrame* GetTreeFrame();
void SetAllowEvents(PRBool allowEvents) { mAllowEvents = allowEvents; };
void SetAnonymousContent(nsIContent* aAnonymousContent) { mAnonymousContent = aAnonymousContent; };
void ToggleOpenClose();
void Open();
void Close();
protected:
nsTreeCellFrame();
virtual ~nsTreeCellFrame();
nsresult HandleMouseDownEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
nsresult HandleMouseEnterEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
nsresult HandleMouseExitEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
nsresult HandleDoubleClickEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
PRBool CanResize(nsPoint& aPoint, nsTableColFrame** aResult);
NS_IMETHOD DidSetStyleContext(nsIPresContext* aPresContext) { return NS_OK; };
protected:
// Data members
PRBool mIsHeader; // Whether or not we're a column header
nsTreeFrame* mTreeFrame; // Our parent tree frame.
PRBool mAllowEvents; // Whether we let events go through.
nsIContent* mAnonymousContent; // Our anonymous titledbutton [WEAK ref]
}; // class nsTableCellFrame

View File

@@ -1,430 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsCOMPtr.h"
#include "nsTreeFrame.h"
#include "nsIStyleContext.h"
#include "nsIContent.h"
#include "nsCSSRendering.h"
#include "nsTreeCellFrame.h"
#include "nsTableColFrame.h"
#include "nsCellMap.h"
#include "nsIDOMXULTreeElement.h"
#include "nsINameSpaceManager.h"
#include "nsTreeRowGroupFrame.h"
#include "nsXULAtoms.h"
#include "nsHTMLAtoms.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMXULTreeElement.h"
#include "nsTreeTwistyListener.h"
#include "nsIPresContext.h"
#include "nsIPresShell.h"
#include "nsIReflowCommand.h"
#include "nsHTMLParts.h"
//
// NS_NewTreeFrame
//
// Creates a new tree frame
//
nsresult
NS_NewTreeFrame (nsIFrame** aNewFrame)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsTreeFrame* it = new nsTreeFrame;
if (!it)
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = it;
return NS_OK;
} // NS_NewTreeFrame
// Constructor
nsTreeFrame::nsTreeFrame()
:nsTableFrame(),mSlatedForReflow(PR_FALSE), mTwistyListener(nsnull), mGeneration(0), mUseGeneration(PR_TRUE) { }
// Destructor
nsTreeFrame::~nsTreeFrame()
{
}
void nsTreeFrame::SetSelection(nsIPresContext& aPresContext, nsTreeCellFrame* aFrame)
{
nsCOMPtr<nsIContent> cellContent;
aFrame->GetContent(getter_AddRefs(cellContent));
if (!cellContent) return;
nsCOMPtr<nsIContent> rowContent;
cellContent->GetParent(*getter_AddRefs(rowContent));
nsCOMPtr<nsIContent> itemContent;
rowContent->GetParent(*getter_AddRefs(itemContent));
nsCOMPtr<nsIDOMXULTreeElement> treeElement = do_QueryInterface(mContent);
nsCOMPtr<nsIDOMXULElement> cellElement = do_QueryInterface(cellContent);
nsCOMPtr<nsIDOMXULElement> itemElement = do_QueryInterface(itemContent);
nsCOMPtr<nsIAtom> kSuppressSelectChange = dont_AddRef(NS_NewAtom("suppressonselect"));
mContent->SetAttribute(kNameSpaceID_None, kSuppressSelectChange, "true", PR_FALSE);
treeElement->SelectItem(itemElement);
mContent->UnsetAttribute(kNameSpaceID_None, kSuppressSelectChange, PR_FALSE);
treeElement->SelectCell(cellElement);
}
void nsTreeFrame::ToggleSelection(nsIPresContext& aPresContext, nsTreeCellFrame* aFrame)
{
nsCOMPtr<nsIContent> cellContent;
aFrame->GetContent(getter_AddRefs(cellContent));
nsCOMPtr<nsIContent> rowContent;
cellContent->GetParent(*getter_AddRefs(rowContent));
nsCOMPtr<nsIContent> itemContent;
rowContent->GetParent(*getter_AddRefs(itemContent));
nsCOMPtr<nsIDOMXULTreeElement> treeElement = do_QueryInterface(mContent);
nsCOMPtr<nsIDOMXULElement> cellElement = do_QueryInterface(cellContent);
nsCOMPtr<nsIDOMXULElement> itemElement = do_QueryInterface(itemContent);
nsCOMPtr<nsIAtom> kSuppressSelectChange = dont_AddRef(NS_NewAtom("suppressonselect"));
mContent->SetAttribute(kNameSpaceID_None, kSuppressSelectChange, "true", PR_FALSE);
treeElement->ToggleItemSelection(itemElement);
mContent->UnsetAttribute(kNameSpaceID_None, kSuppressSelectChange, PR_FALSE);
treeElement->ToggleCellSelection(cellElement);
}
void nsTreeFrame::RangedSelection(nsIPresContext& aPresContext, nsTreeCellFrame* pEndFrame)
{
// XXX Re-implement!
}
void
nsTreeFrame::GetTreeBody(nsTreeRowGroupFrame** aResult)
{
nsIFrame* curr = mFrames.FirstChild();
while (curr) {
nsCOMPtr<nsIContent> content;
curr->GetContent(getter_AddRefs(content));
if (content) {
nsCOMPtr<nsIAtom> tag;
content->GetTag(*getter_AddRefs(tag));
if (tag && tag.get() == nsXULAtoms::treechildren) {
// This is our actual treechildren frame.
nsTreeRowGroupFrame* rowGroup = (nsTreeRowGroupFrame*)curr; // XXX I am evil.
*aResult = rowGroup;
return;
}
}
curr->GetNextSibling(&curr);
}
}
NS_IMETHODIMP
nsTreeFrame::HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
aEventStatus = nsEventStatus_eConsumeDoDefault;
if (aEvent->message == NS_KEY_DOWN) {
nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
PRUint32 keyCode = keyEvent->keyCode;
if (keyCode == NS_VK_UP ||
keyCode == NS_VK_DOWN ||
keyCode == NS_VK_LEFT ||
keyCode == NS_VK_RIGHT ||
keyCode == NS_VK_ENTER) {
// Get our treechildren child frame.
nsTreeRowGroupFrame* treeRowGroup = nsnull;
GetTreeBody(&treeRowGroup);
if (!treeRowGroup)
return NS_OK; // No tree body. Just bail.
nsCOMPtr<nsIDOMXULTreeElement> treeElement = do_QueryInterface(mContent);
nsCOMPtr<nsIDOMNodeList> itemNodeList;
nsCOMPtr<nsIDOMNodeList> cellNodeList;
treeElement->GetSelectedItems(getter_AddRefs(itemNodeList));
treeElement->GetSelectedCells(getter_AddRefs(cellNodeList));
PRUint32 itemLength;
PRUint32 cellLength;
itemNodeList->GetLength(&itemLength);
cellNodeList->GetLength(&cellLength);
PRInt32 rowIndex = -1;
PRInt32 cellIndex = 0;
if (cellLength != 0 && itemLength == 0) {
nsCOMPtr<nsIDOMNode> node;
cellNodeList->Item(0, getter_AddRefs(node));
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
treeRowGroup->IndexOfCell(aPresContext, content, rowIndex, cellIndex);
}
else if (cellLength == 0 && itemLength != 0) {
nsCOMPtr<nsIDOMNode> node;
itemNodeList->Item(0, getter_AddRefs(node));
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
treeRowGroup->IndexOfRow(aPresContext, content, rowIndex);
}
else if (cellLength != 0 && itemLength != 0) {
nsCOMPtr<nsIDOMNode> node;
cellNodeList->Item(0, getter_AddRefs(node));
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
treeRowGroup->IndexOfCell(aPresContext, content, rowIndex, cellIndex);
}
// We now have a valid row and cell index for the current selection. Based on the
// direction, let's adjust the row and column index.
if (rowIndex == -1)
rowIndex = 0;
else if (keyCode == NS_VK_DOWN)
rowIndex++;
else if (keyCode == NS_VK_UP)
rowIndex--;
// Ensure that the required index is visible.
treeRowGroup->EnsureRowIsVisible(rowIndex);
// now that it's (probably) been brought into view, is it valid?
// if (!treeRowGroup->IsValidRow(rowIndex))
// return NS_OK;
// Now that the row is scrolled into view, we have a frame created. We can retrieve the cell.
nsTreeCellFrame* cellFrame=nsnull;
treeRowGroup->GetCellFrameAtIndex(rowIndex, cellIndex, &cellFrame);
if (!cellFrame)
return NS_OK; // No cell. Whatever. Bail.
// We got it! Perform the selection on an up/down.
if (keyCode == NS_VK_UP || keyCode == NS_VK_DOWN)
SetSelection(aPresContext, cellFrame);
else if (keyCode == NS_VK_ENTER || keyCode == NS_VK_RETURN)
cellFrame->ToggleOpenClose();
else if (keyCode == NS_VK_LEFT)
cellFrame->Close();
else if (keyCode == NS_VK_RIGHT)
cellFrame->Open();
}
}
return NS_OK;
}
void nsTreeFrame::MoveUp(nsIPresContext& aPresContext, nsTreeCellFrame* pFrame)
{
PRInt32 rowIndex;
pFrame->GetRowIndex(rowIndex);
PRInt32 colIndex;
pFrame->GetColIndex(colIndex);
if (rowIndex > 0)
{
MoveToRowCol(aPresContext, rowIndex-1, colIndex);
}
}
void nsTreeFrame::MoveDown(nsIPresContext& aPresContext, nsTreeCellFrame* pFrame)
{
PRInt32 rowIndex;
pFrame->GetRowIndex(rowIndex);
PRInt32 colIndex;
pFrame->GetColIndex(colIndex);
PRInt32 totalRows = mCellMap->GetRowCount();
if (rowIndex < totalRows-1)
{
MoveToRowCol(aPresContext, rowIndex+1, colIndex);
}
}
void nsTreeFrame::MoveLeft(nsIPresContext& aPresContext, nsTreeCellFrame* pFrame)
{
PRInt32 rowIndex;
pFrame->GetRowIndex(rowIndex);
PRInt32 colIndex;
pFrame->GetColIndex(colIndex);
if (colIndex > 0)
{
MoveToRowCol(aPresContext, rowIndex, colIndex-1);
}
}
void nsTreeFrame::MoveRight(nsIPresContext& aPresContext, nsTreeCellFrame* aFrame)
{
PRInt32 rowIndex;
aFrame->GetRowIndex(rowIndex);
PRInt32 colIndex;
aFrame->GetColIndex(colIndex);
PRInt32 totalCols = mCellMap->GetColCount();
if (colIndex < totalCols-1)
{
MoveToRowCol(aPresContext, rowIndex, colIndex+1);
}
}
void nsTreeFrame::MoveToRowCol(nsIPresContext& aPresContext, PRInt32 aRow, PRInt32 aCol)
{
nsTableCellFrame* cellFrame = mCellMap->GetCellInfoAt(aRow, aCol);
// We now have the cell that should be selected.
nsTreeCellFrame* treeCell = NS_STATIC_CAST(nsTreeCellFrame*, cellFrame);
SetSelection(aPresContext, treeCell);
}
NS_IMETHODIMP
nsTreeFrame::Destroy(nsIPresContext& aPresContext)
{
nsCOMPtr<nsIDOMEventReceiver> target = do_QueryInterface(mContent);
target->RemoveEventListener("mousedown", mTwistyListener, PR_TRUE);
mTwistyListener = nsnull;
return nsTableFrame::Destroy(aPresContext);
}
NS_IMETHODIMP
nsTreeFrame::Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
nsresult rv = NS_OK;
mSlatedForReflow = PR_FALSE;
if (!mSuppressReflow) {
nsRect rect;
GetRect(rect);
if (rect.width != aReflowState.mComputedWidth && aReflowState.reason == eReflowReason_Resize) {
// We're doing a resize and changing the width of the table. All rows must
// reflow. Reset our generation.
SetUseGeneration(PR_FALSE);
}
if (UseGeneration()) {
++mGeneration;
}
rv = nsTableFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
}
else
{
aStatus = NS_FRAME_COMPLETE;
}
if (aReflowState.mComputedWidth != NS_UNCONSTRAINEDSIZE)
aDesiredSize.width = aReflowState.mComputedWidth +
aReflowState.mComputedBorderPadding.left + aReflowState.mComputedBorderPadding.right;
if (aReflowState.mComputedHeight != NS_UNCONSTRAINEDSIZE)
aDesiredSize.height = aReflowState.mComputedHeight +
aReflowState.mComputedBorderPadding.top + aReflowState.mComputedBorderPadding.bottom;
aDesiredSize.ascent = aDesiredSize.height;
if (!UseGeneration())
SetUseGeneration(PR_TRUE);
return rv;
}
NS_IMETHODIMP
nsTreeFrame::DidReflow(nsIPresContext& aPresContext,
nsDidReflowStatus aStatus)
{
nsresult rv = nsTableFrame::DidReflow(aPresContext, aStatus);
return rv;
}
NS_IMETHODIMP
nsTreeFrame::MarkForDirtyReflow(nsIPresContext& aPresContext)
{
mSuppressReflow = PR_FALSE;
InvalidateCellMap();
InvalidateColumnCache();
InvalidateFirstPassCache();
nsCOMPtr<nsIPresShell> shell;
aPresContext.GetShell(getter_AddRefs(shell));
nsFrameState frameState;
nsIFrame* tableParentFrame;
nsIReflowCommand* reflowCmd;
// Mark the table frame as dirty
GetFrameState(&frameState);
frameState |= NS_FRAME_IS_DIRTY;
SetFrameState(frameState);
// Target the reflow comamnd at its parent frame
GetParent(&tableParentFrame);
nsresult rv = NS_NewHTMLReflowCommand(&reflowCmd, tableParentFrame,
nsIReflowCommand::ReflowDirty);
if (NS_SUCCEEDED(rv)) {
// Add the reflow command
rv = shell->AppendReflowCommand(reflowCmd);
NS_RELEASE(reflowCmd);
}
return rv;
}
NS_IMETHODIMP
nsTreeFrame::Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsTableFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
// Create the menu bar listener.
mTwistyListener = new nsTreeTwistyListener();
nsCOMPtr<nsIDOMEventReceiver> target = do_QueryInterface(mContent);
target->AddEventListener("mousedown", mTwistyListener, PR_TRUE);
return rv;
}
PRBool
nsTreeFrame::ContainsFlexibleColumn(PRInt32 aStartIndex, PRInt32 aEndIndex,
nsTableColFrame** aResult)
{
for (PRInt32 i = aEndIndex; i >= aStartIndex; i--) {
nsTableColFrame* result = GetColFrame(i);
nsCOMPtr<nsIContent> colContent;
result->GetContent(getter_AddRefs(colContent));
nsCOMPtr<nsIAtom> fixedAtom = dont_AddRef(NS_NewAtom("fixed"));
if (colContent) {
nsAutoString fixedValue;
colContent->GetAttribute(kNameSpaceID_None, fixedAtom, fixedValue);
if (fixedValue != "true") {
// We are a proportional column.
if (aResult)
*aResult = result;
return PR_TRUE;
}
}
}
return PR_FALSE;
}

View File

@@ -1,91 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsTableFrame.h"
#include "nsVoidArray.h"
class nsTreeCellFrame;
class nsTreeRowGroupFrame;
class nsTreeTwistyListener;
class nsTreeFrame : public nsTableFrame
{
public:
friend nsresult NS_NewTreeFrame(nsIFrame** aNewFrame);
void SetSelection(nsIPresContext& presContext, nsTreeCellFrame* pFrame);
void ToggleSelection(nsIPresContext& presContext, nsTreeCellFrame* pFrame);
void RangedSelection(nsIPresContext& aPresContext, nsTreeCellFrame* pEndFrame);
void MoveUp(nsIPresContext& aPresContext, nsTreeCellFrame* pFrame);
void MoveDown(nsIPresContext& aPresContext, nsTreeCellFrame* pFrame);
void MoveLeft(nsIPresContext& aPresContext, nsTreeCellFrame* pFrame);
void MoveRight(nsIPresContext& aPresContext, nsTreeCellFrame* pFrame);
void MoveToRowCol(nsIPresContext& aPresContext, PRInt32 row, PRInt32 col);
PRBool IsSlatedForReflow() { return mSlatedForReflow; };
void SlateForReflow() { mSlatedForReflow = PR_TRUE; };
void GetTreeBody(nsTreeRowGroupFrame** aResult);
// Overridden methods
NS_IMETHOD Destroy(nsIPresContext& aPresContext);
PRBool RowGroupsShouldBeConstrained() { return PR_TRUE; }
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aMetrics,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow);
NS_IMETHOD DidReflow(nsIPresContext& aPresContext,
nsDidReflowStatus aStatus);
PRInt32 GetCurrentGeneration() { return mGeneration; };
void SetCurrentGeneration(PRInt32 aGeneration) { mGeneration = aGeneration; };
PRBool UseGeneration() { return mUseGeneration; };
void SetUseGeneration(PRBool aUse) { mUseGeneration = aUse; };
PRBool ContainsFlexibleColumn(PRInt32 aStartIndex, PRInt32 aEndIndex, nsTableColFrame** aResult);
NS_IMETHOD MarkForDirtyReflow(nsIPresContext& aPresContext);
void SuppressReflow() { mSuppressReflow = PR_TRUE; };
void UnsuppressReflow() { mSuppressReflow = PR_FALSE; };
protected:
nsTreeFrame();
virtual ~nsTreeFrame();
protected: // Data Members
PRBool mSlatedForReflow; // If set, don't waste time scheduling excess reflows.
nsTreeTwistyListener* mTwistyListener;
PRInt32 mGeneration;
PRBool mUseGeneration;
PRBool mSuppressReflow;
}; // class nsTreeFrame

View File

@@ -1,128 +0,0 @@
/* -*- 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 "nsFrame.h"
#include "nsLineLayout.h"
#include "nsHTMLIIDs.h"
#include "nsIPresContext.h"
#include "nsIPresShell.h"
#include "nsXULAtoms.h"
#include "nsUnitConversion.h"
#include "nsIStyleContext.h"
#include "nsIContent.h"
#include "nsStyleConsts.h"
#include "nsINameSpaceManager.h"
#include "nsTreeIndentationFrame.h"
#include "nsCOMPtr.h"
nsTreeIndentationFrame::nsTreeIndentationFrame()
{
mWidth = 0;
mHaveComputedWidth = PR_FALSE;
}
nsresult
NS_NewTreeIndentationFrame(nsIFrame** aNewFrame)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsTreeIndentationFrame* it = new nsTreeIndentationFrame();
if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}
*aNewFrame = it;
return NS_OK;
}
nsTreeIndentationFrame::~nsTreeIndentationFrame()
{
}
NS_IMETHODIMP
nsTreeIndentationFrame::Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aMetrics,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
aStatus = NS_FRAME_COMPLETE;
// By default, we have no area
aMetrics.width = 0;
aMetrics.height = 0;
aMetrics.ascent = 0;
aMetrics.descent = 0;
// Compute our width based on the depth of our node within the content model
if (!mHaveComputedWidth)
{
mWidth = 0;
nscoord level = 0;
// First climb out to the tree item level.
nsIFrame* aFrame = this;
nsCOMPtr<nsIContent> pContent;
aFrame->GetContent(getter_AddRefs(pContent));
nsCOMPtr<nsIAtom> pTag;
pContent->GetTag(*getter_AddRefs(pTag));
if (pTag)
{
while (aFrame && pTag && pTag.get() != nsXULAtoms::treeitem)
{
aFrame->GetParent(&aFrame);
// nsCOMPtr correctly handles releasing the old |pContent| and |pTag|
aFrame->GetContent(getter_AddRefs(pContent));
pContent->GetTag(*getter_AddRefs(pTag));
}
// We now have a tree row content node. Start counting our level of nesting.
nsCOMPtr<nsIContent> pParentContent;
while (pTag.get() != nsXULAtoms::tree && pTag.get() != nsXULAtoms::treehead)
{
pContent->GetParent(*getter_AddRefs(pParentContent));
pParentContent->GetTag(*getter_AddRefs(pTag));
pContent = pParentContent;
++level;
}
level = (level/2) - 1;
if (level < 0) level = 0;
mWidth = level*16; // Hardcode an indentation of 16 pixels for now. TODO: Make this a parameter or something
}
}
float p2t;
aPresContext.GetScaledPixelsToTwips(&p2t);
if (0 != mWidth) {
aMetrics.width = NSIntPixelsToTwips(mWidth, p2t);
}
if (nsnull != aMetrics.maxElementSize) {
aMetrics.maxElementSize->width = aMetrics.width;
aMetrics.maxElementSize->height = aMetrics.height;
}
return NS_OK;
}

View File

@@ -1,37 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
class nsTreeIndentationFrame : public nsFrame {
public:
friend nsresult NS_NewTreeIndentationFrame(nsIFrame** aNewFrame);
// nsIHTMLReflow
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
nsTreeIndentationFrame();
protected:
virtual ~nsTreeIndentationFrame();
nscoord mWidth;
PRBool mHaveComputedWidth;
};

View File

@@ -1,88 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsCOMPtr.h"
#include "nsTreeOuterFrame.h"
#include "nsIStyleContext.h"
#include "nsIContent.h"
#include "nsCSSRendering.h"
#include "nsTreeCellFrame.h"
#include "nsCellMap.h"
#include "nsIDOMXULTreeElement.h"
#include "nsINameSpaceManager.h"
#include "nsXULAtoms.h"
//
// NS_NewTreeOuterFrame
//
// Creates a new tree frame
//
nsresult
NS_NewTreeOuterFrame (nsIFrame** aNewFrame)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsTreeOuterFrame* it = new nsTreeOuterFrame;
if (!it)
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = it;
return NS_OK;
} // NS_NewTreeOuterFrame
// Constructor
nsTreeOuterFrame::nsTreeOuterFrame()
:nsTableOuterFrame() { }
// Destructor
nsTreeOuterFrame::~nsTreeOuterFrame()
{
}
NS_IMETHODIMP
nsTreeOuterFrame::HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
aEventStatus = nsEventStatus_eConsumeDoDefault;
if (aEvent->message == NS_KEY_DOWN) {
// Retrieve the tree frame.
nsIFrame* curr = mFrames.FirstChild();
while (curr) {
nsCOMPtr<nsIContent> content;
curr->GetContent(getter_AddRefs(content));
if (content) {
nsCOMPtr<nsIAtom> tag;
content->GetTag(*getter_AddRefs(tag));
if (tag && tag.get() == nsXULAtoms::tree) {
// This is our actual tree frame.
return curr->HandleEvent(aPresContext, aEvent, aEventStatus);
}
}
curr->GetNextSibling(&curr);
}
}
return NS_OK;
}

View File

@@ -1,37 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsTableOuterFrame.h"
class nsTreeOuterFrame : public nsTableOuterFrame
{
public:
friend nsresult NS_NewTreeOuterFrame(nsIFrame** aNewFrame);
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
protected:
nsTreeOuterFrame();
virtual ~nsTreeOuterFrame();
protected: // Data Members
}; // class nsTreeOuterFrame

View File

@@ -1,405 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsCOMPtr.h"
#include "nsTreeFrame.h"
#include "nsTreeRowFrame.h"
#include "nsIStyleContext.h"
#include "nsIContent.h"
#include "nsCSSRendering.h"
#include "nsTreeCellFrame.h"
#include "nsCellMap.h"
#include "nsIDOMXULTreeElement.h"
#include "nsINameSpaceManager.h"
#include "nsTreeRowGroupFrame.h"
#include "nsXULAtoms.h"
#include "nsHTMLAtoms.h"
#include "nsTableColFrame.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMXULTreeElement.h"
#include "nsTreeTwistyListener.h"
#include "nsIViewManager.h"
#include "nsIView.h"
#include "nsIPresContext.h"
//
// NS_NewTreeFrame
//
// Creates a new tree frame
//
nsresult
NS_NewTreeRowFrame (nsIFrame** aNewFrame)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsTreeRowFrame* it = new nsTreeRowFrame;
if (!it)
return NS_ERROR_OUT_OF_MEMORY;
*aNewFrame = it;
return NS_OK;
} // NS_NewTreeRowFrame
// Constructor
nsTreeRowFrame::nsTreeRowFrame()
:nsTableRowFrame(), mIsHeader(PR_FALSE), mGeneration(0), mDraggingHeader(PR_FALSE),
mHitFrame(nsnull), mFlexingCol(nsnull), mHeaderPosition(0)
{ }
// Destructor
nsTreeRowFrame::~nsTreeRowFrame()
{
}
NS_METHOD nsTreeRowFrame::IR_TargetIsChild(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
RowReflowState& aReflowState,
nsReflowStatus& aStatus,
nsIFrame * aNextFrame)
{
nsRect rect;
GetRect(rect);
nsresult rv = nsTableRowFrame::IR_TargetIsChild(aPresContext, aDesiredSize, aReflowState, aStatus, aNextFrame);
if (rv == NS_OK) {
// Find out if our height changed. With the tree widget, changing the height of a row is a
// big deal, since it may force us to dynamically isntantiate newly exposed frames.
if (rect.height != aDesiredSize.height) {
// Retrieve the table frame and invalidate the cell map.
nsTableFrame* tableFrame = nsnull;
nsTableFrame::GetTableFrame(this, tableFrame);
tableFrame->InvalidateCellMap();
}
}
return rv;
}
NS_IMETHODIMP
nsTreeRowFrame::Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsTableRowFrame::Init(aPresContext, aContent, aParent, aContext,
aPrevInFlow);
// Determine if we're a column header or not.
// Get row group frame
if (aParent != nsnull)
{
// Get the display type of the row group frame and see if it's a header or body
nsCOMPtr<nsIStyleContext> parentContext;
aParent->GetStyleContext(getter_AddRefs(parentContext));
if (parentContext)
{
const nsStyleDisplay* display = (const nsStyleDisplay*)
parentContext->GetStyleData(eStyleStruct_Display);
if (display->mDisplay == NS_STYLE_DISPLAY_TABLE_HEADER_GROUP)
{
mIsHeader = PR_TRUE;
// headers get their own views, so that they can capture events
CreateViewForFrame(aPresContext,this,aContext,PR_TRUE);
nsIView* view;
GetView(&aPresContext, &view);
view->SetContentTransparency(PR_TRUE);
}
else
{
mIsHeader = PR_FALSE;
// Determine the row's generation.
nsTableFrame* tableFrame;
nsTableFrame::GetTableFrame(aParent, tableFrame);
nsTreeFrame* treeFrame = (nsTreeFrame*)tableFrame;
mGeneration = treeFrame->GetCurrentGeneration();
}
}
}
return rv;
}
NS_IMETHODIMP
nsTreeRowFrame::HeaderDrag(nsIPresContext* aPresContext, PRBool aGrabMouseEvents)
{
// get its view
nsIView* view = nsnull;
GetView(aPresContext, &view);
nsCOMPtr<nsIViewManager> viewMan;
PRBool result;
if (view) {
view->GetViewManager(*getter_AddRefs(viewMan));
if (viewMan) {
if (aGrabMouseEvents) {
viewMan->GrabMouseEvents(view,result);
mDraggingHeader = PR_TRUE;
} else {
viewMan->GrabMouseEvents(nsnull,result);
mDraggingHeader = PR_FALSE;
}
}
}
return NS_OK;
}
NS_IMETHODIMP
nsTreeRowFrame::Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
/*
if (aReflowState.reason != eReflowReason_Incremental) {
// Determine the row's generation.
nsTableFrame* tableFrame;
nsTableFrame::GetTableFrame(this, tableFrame);
nsTreeFrame* treeFrame = (nsTreeFrame*)tableFrame;
if (treeFrame->UseGeneration()) {
PRInt32 currGeneration = treeFrame->GetCurrentGeneration();
if (currGeneration > mGeneration) {
nsRect rect;
GetRect(rect);
aDesiredSize.width = rect.width;
aDesiredSize.height = rect.height;
aStatus = NS_FRAME_COMPLETE;
return NS_OK;
}
}
}
*/
/* static int i = 0;
i++;
printf("Full row reflow! Number %d\n", i);
*/
return nsTableRowFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
}
nsresult
nsTreeRowFrame::HandleMouseUpEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
if (DraggingHeader()) {
HeaderDrag(&aPresContext, PR_FALSE);
}
return NS_OK;
}
NS_IMETHODIMP
nsTreeRowFrame::HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
aEventStatus = nsEventStatus_eConsumeDoDefault;
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP)
HandleMouseUpEvent(aPresContext, aEvent, aEventStatus);
else if (aEvent->message == NS_MOUSE_MOVE && mDraggingHeader && mHitFrame)
HandleHeaderDragEvent(aPresContext, aEvent, aEventStatus);
return NS_OK;
}
NS_IMETHODIMP
nsTreeRowFrame::GetFrameForPoint(nsIPresContext* aPresContext,
const nsPoint& aPoint, // Overridden to capture events
nsIFrame** aFrame)
{
nsresult rv = nsTableRowFrame::GetFrameForPoint(aPresContext, aPoint, aFrame);
if (mDraggingHeader) {
mHitFrame = *aFrame;
*aFrame = this;
nsRect rect;
GetRect(rect);
if (rect.x > aPoint.x || (rect.x+rect.width < aPoint.x)) {
mHitFrame = nsnull;
}
}
return rv;
}
NS_IMETHODIMP
nsTreeRowFrame::GetCursor(nsIPresContext& aPresContext,
nsPoint& aPoint,
PRInt32& aCursor)
{
if (mDraggingHeader) {
nsRect rect;
GetRect(rect);
if (rect.x > aPoint.x || (rect.x+rect.width < aPoint.x)) {
aCursor = NS_STYLE_CURSOR_DEFAULT;
}
else {
aCursor = NS_STYLE_CURSOR_W_RESIZE;
}
}
else aCursor = NS_STYLE_CURSOR_DEFAULT;
return NS_OK;
}
nsresult
nsTreeRowFrame::HandleHeaderDragEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus)
{
// Grab our tree frame.
nsTableFrame* tableFrame = nsnull;
nsTableFrame::GetTableFrame(this, tableFrame);
nsTreeFrame* treeFrame = (nsTreeFrame*)tableFrame;
// Until we finish all of our batched operations, suppress all reflow.
treeFrame->SuppressReflow();
PRInt32 columnCount = treeFrame->GetColCount();
PRInt32* colWidths = new PRInt32[columnCount];
nsCRT::memset(colWidths, 0, columnCount*sizeof(PRInt32));
// Retrieve our column widths.
PRInt32 i;
for (i = 0; i < columnCount; i++) {
nsTableColFrame* result = treeFrame->GetColFrame(i);
nsCOMPtr<nsIContent> colContent;
result->GetContent(getter_AddRefs(colContent));
nsCOMPtr<nsIAtom> fixedAtom = dont_AddRef(NS_NewAtom("fixed"));
if (colContent) {
nsAutoString fixedValue;
colContent->GetAttribute(kNameSpaceID_None, fixedAtom, fixedValue);
if (fixedValue != "true") {
// We are a proportional column and should be annotated with our current
// width.
PRInt32 colWidth = treeFrame->GetColumnWidth(i);
colWidths[i] = colWidth;
}
}
}
// Annotate with the current proportions
for (i = 0; i < columnCount; i++) {
if (colWidths[i] > 0) {
nsTableColFrame* result = treeFrame->GetColFrame(i);
nsCOMPtr<nsIContent> colContent;
result->GetContent(getter_AddRefs(colContent));
if (colContent) {
PRInt32 colWidth = colWidths[i];
char ch[100];
sprintf(ch,"%d*", colWidth);
nsAutoString propColWidth(ch);
colContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::width, propColWidth,
PR_TRUE);
}
}
}
// Figure out how much we shifted the mouse.
char ch[100];
nsPoint point = ((nsMouseEvent*)aEvent)->point;
PRInt32 delta = mHeaderPosition - point.x;
mHeaderPosition = point.x;
// The proportional columns to the right will gain or lose space
// according to the percentages they currently consume.
nscoord propTotal = 0;
// Find our flexing col and note its index and width.
PRInt32 colX;
PRInt32 flexWidth = 0;
PRInt32 flexIndex = 0;
for (colX = 0; colX < columnCount; colX++) {
// Get column information
nsTableColFrame* colFrame = tableFrame->GetColFrame(colX);
if (colFrame == mFlexingCol) {
flexWidth = colWidths[colX];
flexIndex = colX;
break;
}
}
for (colX = flexIndex+1; colX < columnCount; colX++) {
// Retrieve the current widths for these columns and compute
// the total amount of space they occupy.
propTotal += colWidths[colX];
}
// Iterate over the columns to the right of the flexing column,
// and give them a percentage of the delta based off their proportions.
nsCOMPtr<nsIContent> colContent;
nsTableColFrame* colFrame;
PRInt32 colWidth = 0;
PRInt32 remaining = delta;
for (colX = flexIndex+1; colX < columnCount; colX++) {
if (colWidths[colX] > 0) {
colFrame = tableFrame->GetColFrame(colX);
float percentage = ((float)colWidths[colX])/((float)propTotal);
PRInt32 mod = (PRInt32)(percentage * (float)delta);
colWidth = colWidths[colX] + mod;
sprintf(ch,"%d*", colWidth);
nsAutoString propColWidth(ch);
colFrame->GetContent(getter_AddRefs(colContent));
if (colContent) {
colContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::width, propColWidth,
PR_TRUE);
}
remaining -= mod;
}
}
// Fix the spillover. We'll probably be off by a little.
if (remaining != 0 && colContent) {
colWidth += remaining;
sprintf(ch,"%d*", colWidth);
nsAutoString propColWidth(ch);
colContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::width, propColWidth,
PR_TRUE);
}
// Delete the colWidths array.
delete []colWidths;
// Modify the flexing column by the delta.
nsCOMPtr<nsIContent> flexContent;
mFlexingCol->GetContent(getter_AddRefs(flexContent));
if (flexContent) {
treeFrame->SetUseGeneration(PR_FALSE); // Cached rows have to reflow.
treeFrame->UnsuppressReflow();
colWidth = flexWidth - delta;
sprintf(ch,"%d*", colWidth);
nsAutoString propColWidth(ch);
flexContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::width, propColWidth,
PR_TRUE); // NOW we send the notification that causes the reflow.
// Do a dirty table reflow.
//treeFrame->MarkForDirtyReflow(aPresContext);
}
return NS_OK;
}

View File

@@ -1,87 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsTableRowFrame.h"
#include "nsVoidArray.h"
class nsTreeCellFrame;
class nsTreeRowGroupFrame;
class nsTableColFrame;
class nsTreeRowFrame : public nsTableRowFrame
{
public:
friend nsresult NS_NewTreeRowFrame(nsIFrame** aNewFrame);
// Overridden methods
NS_IMETHOD IR_TargetIsChild(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
RowReflowState& aReflowState,
nsReflowStatus& aStatus,
nsIFrame * aNextFrame);
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow); // Overridden to set whether we're a column header
NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext,
const nsPoint& aPoint, // Overridden to capture events
nsIFrame** aFrame);
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD HandleMouseUpEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD HandleHeaderDragEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD GetCursor(nsIPresContext& aPresContext,
nsPoint& aPoint,
PRInt32& aCursor);
NS_IMETHOD HeaderDrag(nsIPresContext* aPresContext, PRBool aGrabber);
PRBool DraggingHeader() { return mDraggingHeader; };
void SetFlexingColumn(nsTableColFrame* aTableColFrame) { mFlexingCol = aTableColFrame; };
void SetHeaderPosition(PRInt32 aHeaderPos) { mHeaderPosition = aHeaderPos; };
protected:
nsTreeRowFrame();
virtual ~nsTreeRowFrame();
protected: // Data Members
PRBool mIsHeader;
PRInt32 mGeneration;
PRBool mDraggingHeader;
nsIFrame* mHitFrame;
nsTableColFrame* mFlexingCol;
PRInt32 mHeaderPosition;
}; // class nsTreeRowFrame

File diff suppressed because it is too large Load Diff

View File

@@ -1,193 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsTableRowGroupFrame.h"
#include "nsVoidArray.h"
#include "nsIScrollbarListener.h"
class nsTreeFrame;
class nsCSSFrameConstructor;
class nsISupportsArray;
class nsTreeRowGroupFrame : public nsTableRowGroupFrame, public nsIScrollbarListener
{
public:
friend nsresult NS_NewTreeRowGroupFrame(nsIFrame** aNewFrame);
NS_IMETHOD GetAdditionalChildListName(PRInt32 aIndex,
nsIAtom** aListName) const;
NS_IMETHOD FirstChild(nsIAtom* aListName, nsIFrame** aFirstChild) const;
void SetScrollbarFrame(nsIFrame* aFrame);
void SetFrameConstructor(nsCSSFrameConstructor* aFrameConstructor) { mFrameConstructor = aFrameConstructor; };
void SetShouldHaveScrollbar();
void CreateScrollbar(nsIPresContext& aPresContext);
void MakeLazy() { mIsLazy = PR_TRUE; };
PRBool IsLazy() { return mIsLazy; };
NS_IMETHOD TreeAppendFrames(nsIFrame* aFrameList);
NS_IMETHOD TreeInsertFrames(nsIFrame* aPrevFrame,
nsIFrame* aFrameList);
NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext, const nsPoint& aPoint, nsIFrame** aFrame);
void PaintChildren(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
NS_IMETHOD Destroy(nsIPresContext& aPresContext);
PRBool ContinueReflow(nsIPresContext& aPresContext, nscoord y, nscoord height);
PRBool IsFull() { return mIsFull; };
// Responses to changes
void OnContentAdded(nsIPresContext& aPresContext);
void OnContentInserted(nsIPresContext& aPresContext, nsIFrame* aNextSibling);
void OnContentRemoved(nsIPresContext& aPresContext, nsIFrame* aChildFrame);
virtual nsIFrame* GetFirstFrame();
virtual nsIFrame* GetLastFrame();
virtual void GetNextFrame(nsIFrame* aFrame, nsIFrame** aResult);
virtual PRBool RowsDesireExcessSpace() { return PR_FALSE; };
virtual PRBool RowGroupDesiresExcessSpace();
NS_DECL_ISUPPORTS
NS_IMETHOD PositionChanged(nsIPresContext& aPresContext, PRInt32 aOldIndex, PRInt32 aNewIndex);
NS_IMETHOD PagedUpDown();
protected:
nsTreeRowGroupFrame();
virtual ~nsTreeRowGroupFrame();
virtual PRBool RowGroupReceivesExcessSpace();
void DestroyRows(nsTableFrame* aTableFrame, nsIPresContext& aPresContext, PRInt32& rowsToLose);
void ReverseDestroyRows(nsTableFrame* aTableFrame, nsIPresContext& aPresContext, PRInt32& rowsToLose);
NS_IMETHOD ReflowBeforeRowLayout(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
RowGroupReflowState& aReflowState,
nsReflowStatus& aStatus,
nsReflowReason aReason);
NS_IMETHOD ReflowAfterRowLayout(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
RowGroupReflowState& aReflowState,
nsReflowStatus& aStatus,
nsReflowReason aReason);
NS_IMETHOD IR_TargetIsChild(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
RowGroupReflowState& aReflowState,
nsReflowStatus& aStatus,
nsIFrame * aNextFrame);
virtual nsIFrame* GetFirstFrameForReflow(nsIPresContext& aPresContext);
virtual void GetNextFrameForReflow(nsIPresContext& aPresContext, nsIFrame* aFrame, nsIFrame** aResult);
void LocateFrame(nsIFrame* aStartFrame, nsIFrame** aResult);
void SetContentChain(nsISupportsArray* aContentChain);
void InitSubContentChain(nsTreeRowGroupFrame* aRowGroupFrame);
void ConstructContentChain(nsIContent* aRowContent);
void ConstructOldContentChain(nsIPresContext& aPresContext, nsIContent* aOldRowContent);
void CreateOldContentChain(nsIPresContext& aPresContext, nsIContent* aOldRowContent, nsIContent* topOfChain);
void FindChildOfCommonContentChainAncestor(nsIContent *startContent, nsIContent **child);
PRBool IsAncestor(nsIContent *aRowContent, nsIContent *aOldRowContent, nsIContent **firstDescendant);
void FindPreviousRowContent(PRInt32& aDelta, nsIContent* aUpwardHint,
nsIContent* aDownwardHint, nsIContent** aResult);
static void FindRowContentAtIndex(PRInt32& aIndex, nsIContent* aParent,
nsIContent** aResult);
void MarkTreeAsDirty(nsIPresContext& aPresContext, nsTreeFrame* aTreeFrame);
void GetFirstRowContent(nsIContent** aRowContent);
void ComputeVisibleRowCount(PRInt32& rowCount, nsIContent* aParent);
void PostAppendRow(nsIFrame* aRowFrame, nsIPresContext& aPresContext);
public:
// Helpers that allow access to info. The tree is the primary consumer of this
// info.
// Tells you the row and index of a cell (given only the content node).
// This method is expensive.
void IndexOfCell(nsIPresContext& aPresContext, nsIContent* aCellContent,
PRInt32& aRowIndex, PRInt32& aColIndex);
// Tells you the row index of a row (given only the content node).
// This method is expensive.
void IndexOfRow(nsIPresContext& aPresContext, nsIContent* aRowContent, PRInt32& aRowIndex);
// Whether or not the row is valid. This is a cheap method, since the total row count
// is cached.
PRBool IsValidRow(PRInt32 aRowIndex);
// This method ensures that a row is onscreen. It will scroll the tree widget such
// that the row is at the top of the screen (if the row was offscreen to start with).
void EnsureRowIsVisible(PRInt32 aRowIndex);
// This method retrieves a cell at a given index. The intent of this method is that it be
// cheap. It should not cause frames to be built, so this should only be called when the
// cell is onscreen (use EnsureRowIsVisible to guarantee this).
void GetCellFrameAtIndex(PRInt32 aRowIndex, PRInt32 aColIndex, nsTreeCellFrame** aResult);
PRInt32 GetVisibleRowCount() { return mRowCount; };
#if 0
static PRInt32 ChildrenAbove(nsIContent *parent, nsIContent *item);
static PRInt32 RecursiveTagCount(nsIContent *node, nsIAtom *tag);
static nsresult FindParentWithTag(nsIContent *node, nsIAtom *tag,
nsIContent **node);
#endif
static PRBool IsTableRowGroupFrame(nsIFrame*);
static PRBool IsTableRowFrame(nsIFrame*);
protected: // Data Members
nsIFrame* mTopFrame; // The current topmost frame in the view.
nsIFrame* mBottomFrame; // The current bottom frame in the view.
nsIFrame* mLinkupFrame; // An old top frame that we're trying to link up with.
PRBool mIsLazy; // Whether or not we're a lazily instantiated beast
PRBool mIsFull; // Whether or not we have any more room.
nsIFrame* mScrollbar; // Our scrollbar.
nsFrameList mScrollbarList; // A frame list that holds our scrollbar.
PRBool mShouldHaveScrollbar; // Whether or not we could potentially have a scrollbar.
nsISupportsArray* mContentChain; // Our content chain
nsCSSFrameConstructor* mFrameConstructor; // We don't own this. (No addref/release allowed, punk.)
nscoord mRowGroupHeight; // The height of the row group.
PRInt32 mCurrentIndex; // Our current scrolled index.
PRInt32 mRowCount; // The current number of visible rows.
}; // class nsTreeRowGroupFrame

View File

@@ -1,137 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsTreeTwistyListener.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMEventListener.h"
#include "nsCOMPtr.h"
#include "nsIDOMUIEvent.h"
#include "nsIPresContext.h"
#include "nsIContent.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsXULAtoms.h"
/*
* nsTreeTwistyListener implementation
*/
NS_IMPL_ADDREF(nsTreeTwistyListener)
NS_IMPL_RELEASE(nsTreeTwistyListener)
////////////////////////////////////////////////////////////////////////
nsTreeTwistyListener::nsTreeTwistyListener()
{
NS_INIT_REFCNT();
}
////////////////////////////////////////////////////////////////////////
nsTreeTwistyListener::~nsTreeTwistyListener()
{
}
////////////////////////////////////////////////////////////////////////
nsresult
nsTreeTwistyListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(nsCOMTypeInfo<nsIDOMEventReceiver>::GetIID())) {
*aInstancePtr = (void*)(nsIDOMEventListener*)(nsIDOMKeyListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsCOMTypeInfo<nsIDOMMouseListener>::GetIID())) {
*aInstancePtr = (void*)(nsIDOMMouseListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
*aInstancePtr = (void*)(nsISupports*)(nsIDOMKeyListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////
static void GetTreeItem(nsIDOMElement* aElement, nsIDOMElement** aResult)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
while (content) {
nsCOMPtr<nsIAtom> tag;
content->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::treeitem) {
nsCOMPtr<nsIDOMElement> result = do_QueryInterface(content);
*aResult = result.get();
NS_IF_ADDREF(*aResult);
return;
}
nsCOMPtr<nsIContent> parent;
content->GetParent(*getter_AddRefs(parent));
content = parent;
}
}
nsresult
nsTreeTwistyListener::MouseDown(nsIDOMEvent* aEvent)
{
// Get the target of the event. If it's a titledbutton, we care.
nsCOMPtr<nsIDOMNode> target;
aEvent->GetTarget(getter_AddRefs(target));
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
if (!element)
return NS_OK;
nsAutoString tagName;
element->GetTagName(tagName);
if (tagName == "titledbutton") {
// Find out if we're the twisty.
nsAutoString classAttr;
element->GetAttribute("class", classAttr);
if (classAttr == "twisty") {
// Retrieve the parent treeitem.
nsCOMPtr<nsIDOMElement> treeItem;
GetTreeItem(element, getter_AddRefs(treeItem));
if (!treeItem)
return NS_OK;
// Eat the event.
aEvent->PreventCapture();
aEvent->PreventBubble();
nsAutoString open;
treeItem->GetAttribute("open", open);
if (open == "true")
treeItem->RemoveAttribute("open");
else treeItem->SetAttribute("open", "true");
}
}
return NS_OK;
}

View File

@@ -1,54 +0,0 @@
/* -*- 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 "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/NPL/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsTreeTwistyListener_h__
#define nsTreeTwistyListener_h__
#include "nsIDOMMouseListener.h"
#include "nsIDOMEventReceiver.h"
class nsIPresContext;
/** editor Implementation of the DragListener interface
*/
class nsTreeTwistyListener : public nsIDOMMouseListener
{
public:
/** default constructor
*/
nsTreeTwistyListener();
/** default destructor
*/
virtual ~nsTreeTwistyListener();
virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; };
virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent) { return NS_OK; };
virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent) { return NS_OK; };
virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent) { return NS_OK; };
virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent) { return NS_OK; };
virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent) { return NS_OK; };
NS_DECL_ISUPPORTS
protected:
};
#endif

View File

@@ -1,28 +0,0 @@
#
# 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.
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = src
include $(topsrcdir)/config/rules.mk

View File

@@ -1,22 +0,0 @@
#!nmake
#
# 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.
DEPTH=..\..\..
DIRS=src
include <$(DEPTH)\config\rules.mak>

View File

@@ -1,53 +0,0 @@
#!nmake
#
# 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.
DEPTH=..\..\..\..
LIBRARY_NAME=raptorxulcontent_s
MODULE=raptor
REQUIRES=xpcom raptor pref
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
CPPSRCS= \
nsXULAtoms.cpp \
$(NULL)
CPP_OBJS= \
.\$(OBJDIR)\nsXULAtoms.obj \
$(NULL)
EXPORTS = \
$(NULL)
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\js \
-I..\..\..\html\style\src -I..\..\..\html\base\src -I$(PUBLIC)\dom \
-I..\..\..\html\document\src \
-I$(PUBLIC)\netlib -I..\..\..\base\src -I$(PUBLIC)\pref
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
include <$(DEPTH)\config\rules.mak>
libs:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

View File

@@ -1,129 +0,0 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/******
This file contains the list of all XUL nsIAtoms and their values
It is designed to be used as inline input to nsXULAtoms.cpp *only*
through the magic of C preprocessing.
All entires must be enclosed in the macro XUL_ATOM which will have cruel
and unusual things done to it
It is recommended (but not strictly necessary) to keep all entries
in alphabetical order
The first argument to XUL_ATOM is the C++ identifier of the atom
The second argument is the string value of the atom
******/
XUL_ATOM(button, "button")
XUL_ATOM(spinner, "spinner")
XUL_ATOM(scrollbar, "scrollbar")
XUL_ATOM(slider, "slider")
XUL_ATOM(colorpicker, "colorpicker")
XUL_ATOM(palettename, "palettename")
XUL_ATOM(fontpicker, "fontpicker")
XUL_ATOM(radio, "radio")
XUL_ATOM(text, "text")
XUL_ATOM(toolbar, "toolbar")
XUL_ATOM(toolbaritem, "toolbaritem")
XUL_ATOM(toolbox, "toolbox")
// The tree atoms
XUL_ATOM(tree, "tree") // The start of a tree view
XUL_ATOM(treecaption, "treecaption") // The caption of a tree view
XUL_ATOM(treehead, "treehead") // The header of the tree view
XUL_ATOM(treerow, "treerow") // A row in the tree view
XUL_ATOM(treecell, "treecell") // An item in the tree view
XUL_ATOM(treeitem, "treeitem") // A cell in the tree view
XUL_ATOM(treechildren, "treechildren") // The children of an item in the tree view
XUL_ATOM(treeindentation, "treeindentation") // Specifies that the indentation for the level should occur here.
XUL_ATOM(allowevents, "allowevents") // Lets events be handled on the cell contents or in menus.
XUL_ATOM(treecol, "treecol") // A column in the tree view
XUL_ATOM(treecolgroup, "treecolgroup") // A column group in the tree view
XUL_ATOM(treefoot, "treefoot") // The footer of the tree view
XUL_ATOM(treepusher, "treepusher") // A column pusher (left or right) for the tree view
XUL_ATOM(scrollbarlist, "scrollbarlist") // An atom for internal use by the tree view
XUL_ATOM(open, "open") // Whether or not a menu, tree, etc. is open
XUL_ATOM(menubar, "menubar") // An XP menu bar.
XUL_ATOM(menu, "menu") // Represents an XP menu
XUL_ATOM(menuitem, "menuitem") // Represents an XP menu item
XUL_ATOM(menupopup, "menupopup") // The XP menu's children.
XUL_ATOM(menuactive, "menuactive") // Whether or not a menu is active (without necessarily being open)
XUL_ATOM(accesskey, "accesskey") // The shortcut key for a menu or menu item
XUL_ATOM(acceltext, "acceltext") // Text to use for the accelerator
XUL_ATOM(popupset, "popupset") // Contains popup menus, context menus, and tooltips
XUL_ATOM(popup, "popup") // The popup for a context menu, popup menu, or tooltip
XUL_ATOM(menugenerated, "menugenerated") // Internal
XUL_ATOM(key, "key") // A key element
XUL_ATOM(broadcaster, "broadcaster") // A broadcaster
XUL_ATOM(observes, "observes") // The observes element
XUL_ATOM(templateAtom, "template") // A XUL template
XUL_ATOM(progressmeter, "progressmeter")
XUL_ATOM(titledbutton, "titledbutton")
XUL_ATOM(crop, "crop")
XUL_ATOM(mode, "mode")
XUL_ATOM(box, "box")
XUL_ATOM(flex, "flex")
XUL_ATOM(spring, "spring")
XUL_ATOM(deck, "deck")
XUL_ATOM(tabcontrol, "tabcontrol")
XUL_ATOM(tab, "tab")
XUL_ATOM(tabpanel, "tabpanel")
XUL_ATOM(tabpage, "tabpage")
XUL_ATOM(tabbox, "tabbox")
XUL_ATOM(index, "index")
XUL_ATOM(maxpos, "maxpos")
XUL_ATOM(curpos, "curpos")
XUL_ATOM(scrollbarbutton, "scrollbarbutton")
XUL_ATOM(increment, "increment")
XUL_ATOM(pageincrement, "pageincrement")
XUL_ATOM(thumb, "thumb")
XUL_ATOM(toggled, "toggled")
XUL_ATOM(grippy, "grippy")
XUL_ATOM(splitter, "splitter")
XUL_ATOM(collapse, "collapse")
XUL_ATOM(resizebefore, "resizebefore")
XUL_ATOM(resizeafter, "resizeafter")
XUL_ATOM(state, "state")
// toolbar & toolbar d&d atoms
XUL_ATOM(tbDropLocation, "tb-droplocation")
XUL_ATOM(tbDropLocationCoord, "tb-droplocationcoord")
XUL_ATOM(tbDropOn, "tb-dropon")
XUL_ATOM(tbTriggerRepaint, "tb-triggerrepaint")
XUL_ATOM(container, "container")
XUL_ATOM(widget, "widget")
XUL_ATOM(window, "window")
XUL_ATOM(iframe, "iframe")
XUL_ATOM(browser, "browser")
XUL_ATOM(editor, "editor")

View File

@@ -1,68 +0,0 @@
/* -*- 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 "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsXULAtoms.h"
static const char kXULNameSpace[] = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
PRInt32 nsXULAtoms::nameSpaceID;
// define storage for all atoms
#define XUL_ATOM(_name, _value) nsIAtom* nsXULAtoms::_name;
#include "nsXULAtomList.h"
#undef XUL_ATOM
static nsrefcnt gRefCnt = 0;
static nsINameSpaceManager* gNameSpaceManager;
void nsXULAtoms::AddRefAtoms() {
if (gRefCnt == 0) {
/* XUL Atoms registers the XUL name space ID because it's a convenient
place to do this, if you don't want a permanent, "well-known" ID.
*/
if (NS_SUCCEEDED(NS_NewNameSpaceManager(&gNameSpaceManager))) {
// gNameSpaceManager->CreateRootNameSpace(namespace);
nsAutoString nameSpace(kXULNameSpace);
gNameSpaceManager->RegisterNameSpace(nameSpace, nameSpaceID);
} else {
NS_ASSERTION(0, "failed to create xul atoms namespace manager");
}
// now register the atoms
#define XUL_ATOM(_name, _value) _name = NS_NewAtom(_value);
#include "nsXULAtomList.h"
#undef XUL_ATOM
}
++gRefCnt;
}
void nsXULAtoms::ReleaseAtoms() {
NS_PRECONDITION(gRefCnt != 0, "bad release of xul atoms");
if (--gRefCnt == 0) {
#define XUL_ATOM(_name, _value) NS_RELEASE(_name);
#include "nsXULAtomList.h"
#undef XUL_ATOM
NS_IF_RELEASE(gNameSpaceManager);
}
}

View File

@@ -1,54 +0,0 @@
/* -*- 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.
*/
#ifndef nsXULAtoms_h___
#define nsXULAtoms_h___
#include "prtypes.h"
#include "nsIAtom.h"
class nsINameSpaceManager;
/**
* This class wraps up the creation and destruction of the standard
* set of xul atoms used during normal xul handling. This object
* is created when the first xul content object is created, and
* destroyed when the last such content object is destroyed.
*/
class nsXULAtoms {
public:
static void AddRefAtoms();
static void ReleaseAtoms();
// XUL namespace ID, good for the life of the nsXULAtoms object
static PRInt32 nameSpaceID;
/* Declare all atoms
The atom names and values are stored in nsCSSAtomList.h and
are brought to you by the magic of C preprocessing
Add new atoms to nsCSSAtomList and all support logic will be auto-generated
*/
#define XUL_ATOM(_name, _value) static nsIAtom* _name;
#include "nsXULAtomList.h"
#undef XUL_ATOM
};
#endif /* nsXULAtoms_h___ */

View File

@@ -1,22 +0,0 @@
#!nmake
#
# 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.
DEPTH=..\..
DIRS = base content
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,617 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsAVLTree.h"
enum eLean {eLeft,eNeutral,eRight};
struct NS_COM nsAVLNode {
public:
nsAVLNode(void* aValue) {
mLeft=0;
mRight=0;
mSkew=eNeutral;
mValue=aValue;
}
nsAVLNode* mLeft;
nsAVLNode* mRight;
eLean mSkew;
void* mValue;
};
/************************************************************
Now begin the tree class. Don't forget that the comparison
between nodes must occur via the comparitor function,
otherwise all you're testing is pointer addresses.
************************************************************/
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
nsAVLTree::nsAVLTree(nsAVLNodeComparitor& aComparitor,
nsAVLNodeFunctor* aDeallocator) :
mComparitor(aComparitor), mDeallocator(aDeallocator) {
mRoot=0;
mCount=0;
}
static void
avlDeleteTree(nsAVLNode* aNode){
if (aNode) {
avlDeleteTree(aNode->mLeft);
avlDeleteTree(aNode->mRight);
delete aNode;
}
}
/**
*
* @update gess12/27/98
* @param
* @return
*/
nsAVLTree::~nsAVLTree(){
if (mDeallocator) {
ForEachDepthFirst(*mDeallocator);
}
avlDeleteTree(mRoot);
}
class CDoesntExist: public nsAVLNodeFunctor {
public:
CDoesntExist(const nsAVLTree& anotherTree) : mOtherTree(anotherTree) {
}
virtual void* operator()(void* anItem) {
void* result=mOtherTree.FindItem(anItem);
if(result)
return nsnull;
return anItem;
}
protected:
const nsAVLTree& mOtherTree;
};
/**
* This method compares two trees (members by identity).
* @update gess12/27/98
* @param tree to compare against
* @return true if they are identical (contain same stuff).
*/
PRBool nsAVLTree::operator==(const nsAVLTree& aCopy) const{
CDoesntExist functor(aCopy);
void* theItem=FirstThat(functor);
PRBool result=PRBool(!theItem);
return result;
}
/**
*
* @update gess12/27/98
* @param
* @return
*/
static void
avlRotateRight(nsAVLNode*& aRootNode){
nsAVLNode* ptr2;
nsAVLNode* ptr3;
ptr2=aRootNode->mRight;
if(ptr2->mSkew==eRight) {
aRootNode->mRight=ptr2->mLeft;
ptr2->mLeft=aRootNode;
aRootNode->mSkew=eNeutral;
aRootNode=ptr2;
}
else {
ptr3=ptr2->mLeft;
ptr2->mLeft=ptr3->mRight;
ptr3->mRight=ptr2;
aRootNode->mRight=ptr3->mLeft;
ptr3->mLeft=aRootNode;
if(ptr3->mSkew==eLeft)
ptr2->mSkew=eRight;
else ptr2->mSkew=eNeutral;
if(ptr3->mSkew==eRight)
aRootNode->mSkew=eLeft;
else aRootNode->mSkew=eNeutral;
aRootNode=ptr3;
}
aRootNode->mSkew=eNeutral;
return;
}
/**
*
* @update gess12/27/98
* @param
* @return
*/
static void
avlRotateLeft(nsAVLNode*& aRootNode){
nsAVLNode* ptr2;
nsAVLNode* ptr3;
ptr2=aRootNode->mLeft;
if(ptr2->mSkew==eLeft) {
aRootNode->mLeft=ptr2->mRight;
ptr2->mRight=aRootNode;
aRootNode->mSkew=eNeutral;
aRootNode=ptr2;
}
else {
ptr3=ptr2->mRight;
ptr2->mRight=ptr3->mLeft;
ptr3->mLeft=ptr2;
aRootNode->mLeft=ptr3->mRight;
ptr3->mRight=aRootNode;
if(ptr3->mSkew==eRight)
ptr2->mSkew=eLeft;
else ptr2->mSkew=eNeutral;
if(ptr3->mSkew==eLeft)
aRootNode->mSkew=eRight;
else aRootNode->mSkew=eNeutral;
aRootNode=ptr3;
}
aRootNode->mSkew=eNeutral;
return;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static eAVLStatus
avlInsert(nsAVLNode*& aRootNode, nsAVLNode* aNewNode,
nsAVLNodeComparitor& aComparitor) {
eAVLStatus result=eAVL_unknown;
if(!aRootNode) {
aRootNode = aNewNode;
return eAVL_ok;
}
if(aNewNode==aRootNode->mValue) {
return eAVL_duplicate;
}
PRInt32 theCompareResult=aComparitor(aRootNode->mValue,aNewNode->mValue);
if(0 < theCompareResult) { //if(anItem<aRootNode->mValue)
result=avlInsert(aRootNode->mLeft,aNewNode,aComparitor);
if(eAVL_ok==result) {
switch(aRootNode->mSkew){
case eLeft:
avlRotateLeft(aRootNode);
result=eAVL_fail;
break;
case eRight:
aRootNode->mSkew=eNeutral;
result=eAVL_fail;
break;
case eNeutral:
aRootNode->mSkew=eLeft;
break;
} //switch
}//if
} //if
else {
result=avlInsert(aRootNode->mRight,aNewNode,aComparitor);
if(eAVL_ok==result) {
switch(aRootNode->mSkew){
case eLeft:
aRootNode->mSkew=eNeutral;
result=eAVL_fail;
break;
case eRight:
avlRotateRight(aRootNode);
result=eAVL_fail;
break;
case eNeutral:
aRootNode->mSkew=eRight;
break;
} //switch
}
} //if
return result;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static void
avlBalanceLeft(nsAVLNode*& aRootNode, PRBool& delOk){
nsAVLNode* ptr2;
nsAVLNode* ptr3;
eLean balnc2;
eLean balnc3;
switch(aRootNode->mSkew){
case eLeft:
ptr2=aRootNode->mLeft;
balnc2=ptr2->mSkew;
if(balnc2!=eRight) {
aRootNode->mLeft=ptr2->mRight;
ptr2->mRight=aRootNode;
if(balnc2==eNeutral){
aRootNode->mSkew=eLeft;
ptr2->mSkew=eRight;
delOk=PR_FALSE;
}
else{
aRootNode->mSkew=eNeutral;
ptr2->mSkew=eNeutral;
}
aRootNode=ptr2;
}
else{
ptr3=ptr2->mRight;
balnc3=ptr3->mSkew;
ptr2->mRight=ptr3->mLeft;
ptr3->mLeft=ptr2;
aRootNode->mLeft=ptr3->mRight;
ptr3->mRight=aRootNode;
if(balnc3==eRight) {
ptr2->mSkew=eLeft;
}
else {
ptr2->mSkew=eNeutral;
}
if(balnc3==eLeft) {
aRootNode->mSkew=eRight;
}
else {
aRootNode->mSkew=eNeutral;
}
aRootNode=ptr3;
ptr3->mSkew=eNeutral;
}
break;
case eRight:
aRootNode->mSkew=eNeutral;
break;
case eNeutral:
aRootNode->mSkew=eLeft;
delOk=PR_FALSE;
break;
}//switch
return;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static void
avlBalanceRight(nsAVLNode*& aRootNode, PRBool& delOk){
nsAVLNode* ptr2;
nsAVLNode* ptr3;
eLean balnc2;
eLean balnc3;
switch(aRootNode->mSkew){
case eLeft:
aRootNode->mSkew=eNeutral;
break;
case eRight:
ptr2=aRootNode->mRight;
balnc2=ptr2->mSkew;
if(balnc2!=eLeft) {
aRootNode->mRight=ptr2->mLeft;
ptr2->mLeft=aRootNode;
if(balnc2==eNeutral){
aRootNode->mSkew=eRight;
ptr2->mSkew=eLeft;
delOk=PR_FALSE;
}
else{
aRootNode->mSkew=eNeutral;
ptr2->mSkew=eNeutral;
}
aRootNode=ptr2;
}
else{
ptr3=ptr2->mLeft;
balnc3=ptr3->mSkew;
ptr2->mLeft=ptr3->mRight;
ptr3->mRight=ptr2;
aRootNode->mRight=ptr3->mLeft;
ptr3->mLeft=aRootNode;
if(balnc3==eLeft) {
ptr2->mSkew=eRight;
}
else {
ptr2->mSkew=eNeutral;
}
if(balnc3==eRight) {
aRootNode->mSkew=eLeft;
}
else {
aRootNode->mSkew=eNeutral;
}
aRootNode=ptr3;
ptr3->mSkew=eNeutral;
}
break;
case eNeutral:
aRootNode->mSkew=eRight;
delOk=PR_FALSE;
break;
}//switch
return;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static eAVLStatus
avlRemoveChildren(nsAVLNode*& aRootNode,nsAVLNode*& anotherNode, PRBool& delOk){
eAVLStatus result=eAVL_ok;
if(!anotherNode->mRight){
aRootNode->mValue=anotherNode->mValue; //swap
anotherNode=anotherNode->mLeft;
delOk=PR_TRUE;
}
else{
avlRemoveChildren(aRootNode,anotherNode->mRight,delOk);
if(delOk)
avlBalanceLeft(anotherNode,delOk);
}
return result;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
static eAVLStatus
avlRemove(nsAVLNode*& aRootNode, void* anItem, PRBool& delOk,
nsAVLNodeComparitor& aComparitor){
eAVLStatus result=eAVL_ok;
if(!aRootNode)
delOk=PR_FALSE;
else {
PRInt32 cmp=aComparitor(anItem,aRootNode->mValue);
if(cmp<0){
avlRemove(aRootNode->mLeft,anItem,delOk,aComparitor);
if(delOk)
avlBalanceRight(aRootNode,delOk);
}
else if(cmp>0){
avlRemove(aRootNode->mRight,anItem,delOk,aComparitor);
if(delOk)
avlBalanceLeft(aRootNode,delOk);
}
else{ //they match...
nsAVLNode* temp=aRootNode;
if(!aRootNode->mRight) {
aRootNode=aRootNode->mLeft;
delOk=PR_TRUE;
delete temp;
}
else if(!aRootNode->mLeft) {
aRootNode=aRootNode->mRight;
delOk=PR_TRUE;
delete temp;
}
else {
avlRemoveChildren(aRootNode,aRootNode->mLeft,delOk);
if(delOk)
avlBalanceRight(aRootNode,delOk);
}
}
}
return result;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
eAVLStatus
nsAVLTree::AddItem(void* anItem){
eAVLStatus result=eAVL_ok;
nsAVLNode* theNewNode=new nsAVLNode(anItem);
result=avlInsert(mRoot,theNewNode,mComparitor);
if(eAVL_duplicate!=result)
mCount++;
else {
delete theNewNode;
}
return result;
}
/** ------------------------------------------------
*
*
* @update gess 4/22/98
* @param
* @return
*/ //----------------------------------------------
void* nsAVLTree::FindItem(void* aValue) const{
nsAVLNode* result=mRoot;
PRInt32 count=0;
while(result) {
count++;
PRInt32 cmp=mComparitor(aValue,result->mValue);
if(0==cmp) {
//we matched...
break;
}
else if(0>cmp){
//theNode was greater...
result=result->mLeft;
}
else {
//aValue is greater...
result=result->mRight;
}
}
if(result) {
return result->mValue;
}
return nsnull;
}
/**
*
* @update gess12/30/98
* @param
* @return
*/
eAVLStatus
nsAVLTree::RemoveItem(void* aValue){
PRBool delOk=PR_TRUE;
eAVLStatus result=avlRemove(mRoot,aValue,delOk,mComparitor);
if(eAVL_ok==result)
mCount--;
return result;
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
static void
avlForEachDepthFirst(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor){
if(aNode) {
avlForEachDepthFirst(aNode->mLeft,aFunctor);
avlForEachDepthFirst(aNode->mRight,aFunctor);
aFunctor(aNode->mValue);
}
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
void
nsAVLTree::ForEachDepthFirst(nsAVLNodeFunctor& aFunctor) const{
::avlForEachDepthFirst(mRoot,aFunctor);
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
static void
avlForEach(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor) {
if(aNode) {
avlForEach(aNode->mLeft,aFunctor);
aFunctor(aNode->mValue);
avlForEach(aNode->mRight,aFunctor);
}
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
void
nsAVLTree::ForEach(nsAVLNodeFunctor& aFunctor) const{
::avlForEach(mRoot,aFunctor);
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
static void*
avlFirstThat(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor) {
void* result=nsnull;
if(aNode) {
result = avlFirstThat(aNode->mLeft,aFunctor);
if (result) {
return result;
}
result = aFunctor(aNode->mValue);
if (result) {
return result;
}
result = avlFirstThat(aNode->mRight,aFunctor);
}
return result;
}
/**
*
* @update gess9/11/98
* @param
* @return
*/
void*
nsAVLTree::FirstThat(nsAVLNodeFunctor& aFunctor) const{
return ::avlFirstThat(mRoot,aFunctor);
}

View File

@@ -0,0 +1,74 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsAVLTree_h___
#define nsAVLTree_h___
#include "nscore.h"
enum eAVLStatus {eAVL_unknown,eAVL_ok,eAVL_fail,eAVL_duplicate};
struct nsAVLNode;
/**
*
* @update gess12/26/98
* @param anObject1 is the first object to be compared
* @param anObject2 is the second object to be compared
* @return -1,0,1 if object1 is less, equal, greater than object2
*/
class NS_COM nsAVLNodeComparitor {
public:
virtual PRInt32 operator()(void* anItem1,void* anItem2)=0;
};
class NS_COM nsAVLNodeFunctor {
public:
virtual void* operator()(void* anItem)=0;
};
class NS_COM nsAVLTree {
public:
nsAVLTree(nsAVLNodeComparitor& aComparitor, nsAVLNodeFunctor* aDeallocator);
~nsAVLTree(void);
PRBool operator==(const nsAVLTree& aOther) const;
PRInt32 GetCount(void) const {return mCount;}
//main functions...
eAVLStatus AddItem(void* anItem);
eAVLStatus RemoveItem(void* anItem);
void* FindItem(void* anItem) const;
void ForEach(nsAVLNodeFunctor& aFunctor) const;
void ForEachDepthFirst(nsAVLNodeFunctor& aFunctor) const;
void* FirstThat(nsAVLNodeFunctor& aFunctor) const;
protected:
nsAVLNode* mRoot;
PRInt32 mCount;
nsAVLNodeComparitor& mComparitor;
nsAVLNodeFunctor* mDeallocator;
};
#endif /* nsAVLTree_h___ */

View File

@@ -0,0 +1,717 @@
/* -*- 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.
*/
/******************************************************************************************
MODULE NOTES:
This file contains the nsStr data structure.
This general purpose buffer management class is used as the basis for our strings.
It's benefits include:
1. An efficient set of library style functions for manipulating nsStrs
2. Support for 1 and 2 byte character strings (which can easily be increased to n)
3. Unicode awareness and interoperability.
*******************************************************************************************/
#include "nsStr.h"
#include "bufferRoutines.h"
#include "stdio.h" //only used for printf
#include "nsCRT.h"
#include "nsDeque.h"
//static const char* kCallFindChar = "For better performance, call FindChar() for targets whose length==1.";
//static const char* kCallRFindChar = "For better performance, call RFindChar() for targets whose length==1.";
static const PRUnichar gCommonEmptyBuffer[1] = {0};
/**
* This method initializes all the members of the nsStr structure
*
* @update gess10/30/98
* @param
* @return
*/
void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
aDest.mStr=(char*)gCommonEmptyBuffer;
aDest.mLength=0;
aDest.mCapacity=0;
aDest.mCharSize=aCharSize;
aDest.mOwnsBuffer=0;
}
/**
* This method initializes all the members of the nsStr structure
* @update gess10/30/98
* @param
* @return
*/
void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer){
aDest.mStr=(aCString) ? aCString : (char*)gCommonEmptyBuffer;
aDest.mLength=aLength;
aDest.mCapacity=aCapacity;
aDest.mCharSize=aCharSize;
aDest.mOwnsBuffer=aOwnsBuffer;
}
/**
* This member destroys the memory buffer owned by an nsStr object (if it actually owns it)
* @update gess10/30/98
* @param
* @return
*/
void nsStr::Destroy(nsStr& aDest) {
if((aDest.mStr) && (aDest.mStr!=(char*)gCommonEmptyBuffer)) {
Free(aDest);
}
}
/**
* This method gets called when the internal buffer needs
* to grow to a given size. The original contents are not preserved.
* @update gess 3/30/98
* @param aNewLength -- new capacity of string in charSize units
* @return void
*/
PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) {
PRBool result=PR_TRUE;
if(aNewLength>aString.mCapacity) {
result=Realloc(aString,aNewLength);
if(aString.mStr)
AddNullTerminator(aString);
}
return result;
}
/**
* This method gets called when the internal buffer needs
* to grow to a given size. The original contents ARE preserved.
* @update gess 3/30/98
* @param aNewLength -- new capacity of string in charSize units
* @return void
*/
PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) {
PRBool result=PR_TRUE;
if(aNewLength>aDest.mCapacity) {
nsStr theTempStr;
nsStr::Initialize(theTempStr,aDest.mCharSize);
result=EnsureCapacity(theTempStr,aNewLength);
if(result) {
if(aDest.mLength) {
Append(theTempStr,aDest,0,aDest.mLength);
}
Free(aDest);
aDest.mStr = theTempStr.mStr;
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
aDest.mLength=theTempStr.mLength;
aDest.mCapacity=theTempStr.mCapacity;
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
}
}
return result;
}
/**
* Replaces the contents of aDest with aSource, up to aCount of chars.
* @update gess10/30/98
* @param aDest is the nsStr that gets changed.
* @param aSource is where chars are copied from
* @param aCount is the number of chars copied from aSource
*/
void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){
if(&aDest!=&aSource){
Truncate(aDest,0);
Append(aDest,aSource,anOffset,aCount);
}
}
/**
* This method appends the given nsStr to this one. Note that we have to
* pay attention to the underlying char-size of both structs.
* @update gess10/30/98
* @param aDest is the nsStr to be manipulated
* @param aSource is where char are copied from
* @aCount is the number of bytes to be copied
*/
void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){
if(anOffset<aSource.mLength){
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
PRUint32 theLength=(anOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-anOffset);
if(0<theLength){
PRBool isBigEnough=PR_TRUE;
if(aDest.mLength+theLength > aDest.mCapacity) {
isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength);
}
if(isBigEnough) {
//now append new chars, starting at offset
(*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDest.mLength,aSource.mStr,anOffset,theLength);
aDest.mLength+=theLength;
AddNullTerminator(aDest);
}
}
}
}
/**
* This method inserts up to "aCount" chars from a source nsStr into a dest nsStr.
* @update gess10/30/98
* @param aDest is the nsStr that gets changed
* @param aDestOffset is where in aDest the insertion is to occur
* @param aSource is where chars are copied from
* @param aSrcOffset is where in aSource chars are copied from
* @param aCount is the number of chars from aSource to be inserted into aDest
*/
void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount){
//there are a few cases for insert:
// 1. You're inserting chars into an empty string (assign)
// 2. You're inserting onto the end of a string (append)
// 3. You're inserting onto the 1..n-1 pos of a string (the hard case).
if(0<aSource.mLength){
if(aDest.mLength){
if(aDestOffset<aDest.mLength){
PRInt32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
PRInt32 theLength=(aSrcOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-aSrcOffset);
if(aSrcOffset<aSource.mLength) {
//here's the only new case we have to handle.
//chars are really being inserted into our buffer...
if(aDest.mLength+theLength > aDest.mCapacity) {
nsStr theTempStr;
nsStr::Initialize(theTempStr,aDest.mCharSize);
PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength); //grow the temp buffer to the right size
if(isBigEnough) {
if(aDestOffset) {
Append(theTempStr,aDest,0,aDestOffset); //first copy leftmost data...
}
Append(theTempStr,aSource,0,aSource.mLength); //next copy inserted (new) data
PRUint32 theRemains=aDest.mLength-aDestOffset;
if(theRemains) {
Append(theTempStr,aDest,aDestOffset,theRemains); //next copy rightmost data
}
Free(aDest);
aDest.mStr = theTempStr.mStr;
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
aDest.mCapacity=theTempStr.mCapacity;
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
}
}
else {
//shift the chars right by theDelta...
(*gShiftChars[aDest.mCharSize][KSHIFTRIGHT])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
//now insert new chars, starting at offset
(*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength);
}
//finally, make sure to update the string length...
aDest.mLength+=theLength;
AddNullTerminator(aDest);
}//if
//else nothing to do!
}
else Append(aDest,aSource,0,aCount);
}
else Append(aDest,aSource,0,aCount);
}
}
/**
* This method deletes up to aCount chars from aDest
* @update gess10/30/98
* @param aDest is the nsStr to be manipulated
* @param aDestOffset is where in aDest deletion is to occur
* @param aCount is the number of chars to be deleted in aDest
*/
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount){
if(aDestOffset<aDest.mLength){
PRUint32 theDelta=aDest.mLength-aDestOffset;
PRUint32 theLength=(theDelta<aCount) ? theDelta : aCount;
if(aDestOffset+theLength<aDest.mLength) {
//if you're here, it means we're cutting chars out of the middle of the string...
//so shift the chars left by theLength...
(*gShiftChars[aDest.mCharSize][KSHIFTLEFT])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
aDest.mLength-=theLength;
AddNullTerminator(aDest);
}
else Truncate(aDest,aDestOffset);
}//if
}
/**
* This method truncates the given nsStr at given offset
* @update gess10/30/98
* @param aDest is the nsStr to be truncated
* @param aDestOffset is where in aDest truncation is to occur
*/
void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset){
if(aDestOffset<aDest.mLength){
aDest.mLength=aDestOffset;
AddNullTerminator(aDest);
}
}
/**
* This method forces the given string to upper or lowercase
* @update gess1/7/99
* @param aDest is the string you're going to change
* @param aToUpper: if TRUE, then we go uppercase, otherwise we go lowercase
* @return
*/
void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) {
// somehow UnicharUtil return failed, fallback to the old ascii only code
gCaseConverters[aDest.mCharSize](aDest.mStr,aDest.mLength,aToUpper);
}
/**
*
* @update gess1/7/99
* @param
* @return
*/
void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
if((aDest.mLength>0) && aSet){
PRInt32 theIndex=-1;
PRInt32 theMax=aDest.mLength;
PRInt32 theSetLen=nsCRT::strlen(aSet);
if(aEliminateLeading) {
while(++theIndex<=theMax) {
PRUnichar theChar=GetCharAt(aDest,theIndex);
PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE);
if(kNotFound==thePos)
break;
}
if(0<theIndex) {
if(theIndex<theMax) {
Delete(aDest,0,theIndex);
}
else Truncate(aDest,0);
}
}
if(aEliminateTrailing) {
theIndex=aDest.mLength;
PRInt32 theNewLen=theIndex;
while(--theIndex>0) {
PRUnichar theChar=GetCharAt(aDest,theIndex); //read at end now...
PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE);
if(kNotFound<thePos)
theNewLen=theIndex;
else break;
}
if(theNewLen<theMax) {
Truncate(aDest,theNewLen);
}
}
}
}
/**
*
* @update gess1/7/99
* @param
* @return
*/
void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
Trim(aDest,aSet,aEliminateLeading,aEliminateTrailing);
PRUint32 aNewLen=gCompressChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet);
aDest.mLength=aNewLen;
}
/**
*
* @update gess1/7/99
* @param
* @return
*/
void nsStr::StripChars(nsStr& aDest,const char* aSet){
if((0<aDest.mLength) && (aSet)) {
PRUint32 aNewLen=gStripChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet);
aDest.mLength=aNewLen;
}
}
/**************************************************************
Searching methods...
**************************************************************/
/**
* This searches aDest for a given substring
*
* @update gess 3/25/98
* @param aDest string to search
* @param aTarget is the substring you're trying to find.
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRInt32 anOffset) {
// NS_PRECONDITION(aTarget.mLength!=1,kCallFindChar);
PRInt32 result=kNotFound;
if((0<aDest.mLength) && (anOffset<(PRInt32)aDest.mLength)) {
PRInt32 theMax=aDest.mLength-aTarget.mLength;
PRInt32 index=(0<=anOffset) ? anOffset : 0;
if((aDest.mLength>=aTarget.mLength) && (aTarget.mLength>0) && (index>=0)){
PRInt32 theTargetMax=aTarget.mLength;
while(index<=theMax) {
PRInt32 theSubIndex=-1;
PRBool matches=PR_TRUE;
while((++theSubIndex<theTargetMax) && (matches)){
PRUnichar theChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aDest,index+theSubIndex)) : GetCharAt(aDest,index+theSubIndex);
PRUnichar theTargetChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aTarget,theSubIndex)) : GetCharAt(aTarget,theSubIndex);
matches=PRBool(theChar==theTargetChar);
}
if(matches) {
result=index;
break;
}
index++;
} //while
}//if
}//if
return result;
}
/**
* This searches aDest for a given character
*
* @update gess 3/25/98
* @param aDest string to search
* @param char is the character you're trying to find.
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset) {
PRInt32 result=kNotFound;
if((0<aDest.mLength) && (anOffset<(PRInt32)aDest.mLength)) {
PRUint32 index=(0<=anOffset) ? (PRUint32)anOffset : 0;
result=gFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,index,aChar,aIgnoreCase);
}
return result;
}
/**
* This searches aDest for a character found in aSet.
*
* @update gess 3/25/98
* @param aDest string to search
* @param aSet contains a list of chars to be searched for
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset) {
//NS_PRECONDITION(aSet.mLength!=1,kCallFindChar);
PRInt32 index=(0<=anOffset) ? anOffset-1 : -1;
PRInt32 thePos;
//Note that the search is inverted here. We're scanning aDest, one char at a time
//but doing the search against the given set. That's why we use 0 as the offset below.
if((0<aDest.mLength) && (0<aSet.mLength)){
while(++index<(PRInt32)aDest.mLength) {
PRUnichar theChar=GetCharAt(aDest,index);
thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
if(kNotFound!=thePos)
return index;
} //while
}
return kNotFound;
}
/**************************************************************
Reverse Searching methods...
**************************************************************/
/**
* This searches aDest (in reverse) for a given substring
*
* @update gess 3/25/98
* @param aDest string to search
* @param aTarget is the substring you're trying to find.
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search (counting from left)
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRInt32 anOffset) {
//NS_PRECONDITION(aTarget.mLength!=1,kCallRFindChar);
PRInt32 result=kNotFound;
if((0<aDest.mLength) && (anOffset<(PRInt32)aDest.mLength)) {
PRInt32 index=(0<=anOffset) ? anOffset : aDest.mLength-1;
if((aDest.mLength>=aTarget.mLength) && (aTarget.mLength>0) && (index>=0)){
nsStr theCopy;
nsStr::Initialize(theCopy,eOneByte);
nsStr::Assign(theCopy,aTarget,0,aTarget.mLength);
if(aIgnoreCase){
nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase
}
PRInt32 theTargetMax=theCopy.mLength;
while(index>=0) {
PRInt32 theSubIndex=-1;
PRBool matches=PR_FALSE;
if(index+theCopy.mLength<=aDest.mLength) {
matches=PR_TRUE;
while((++theSubIndex<theTargetMax) && (matches)){
PRUnichar theDestChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aDest,index+theSubIndex)) : GetCharAt(aDest,index+theSubIndex);
PRUnichar theTargetChar=GetCharAt(theCopy,theSubIndex);
matches=PRBool(theDestChar==theTargetChar);
} //while
} //if
if(matches) {
result=index;
break;
}
index--;
} //while
nsStr::Destroy(theCopy);
}//if
}//if
return result;
}
/**
* This searches aDest (in reverse) for a given character
*
* @update gess 3/25/98
* @param aDest string to search
* @param char is the character you're trying to find.
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset) {
PRInt32 result=kNotFound;
if((0<aDest.mLength) && (anOffset<(PRInt32)aDest.mLength)) {
PRUint32 index=(0<=anOffset) ? anOffset : aDest.mLength-1;
result=gRFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,index,aChar,aIgnoreCase);
}
return result;
}
/**
* This searches aDest (in reverese) for a character found in aSet.
*
* @update gess 3/25/98
* @param aDest string to search
* @param aSet contains a list of chars to be searched for
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset) {
//NS_PRECONDITION(aSet.mLength!=1,kCallRFindChar);
PRInt32 index=(0<=anOffset) ? anOffset : aDest.mLength;
PRInt32 thePos;
//note that the search is inverted here. We're scanning aDest, one char at a time
//but doing the search against the given set. That's why we use 0 as the offset below.
if(0<aDest.mLength) {
while(--index>=0) {
PRUnichar theChar=GetCharAt(aDest,index);
thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
if(kNotFound!=thePos)
return index;
} //while
}
return kNotFound;
}
/**
* Compare source and dest strings, up to an (optional max) number of chars
* @param aDest is the first str to compare
* @param aSource is the second str to compare
* @param aCount -- if (-1), then we use length of longer string; if (0<aCount) then it gives the max # of chars to compare
* @param aIgnorecase tells us whether to search with case sensitivity
* @return aDest<aSource=-1;aDest==aSource==0;aDest>aSource=1
*/
PRInt32 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) {
PRInt32 result=0;
if(aCount) {
PRInt32 minlen=(aSource.mLength<aDest.mLength) ? aSource.mLength : aDest.mLength;
if(0==minlen) {
if ((aDest.mLength == 0) && (aSource.mLength == 0))
return 0;
if (aDest.mLength == 0)
return -1;
return 1;
}
PRInt32 maxlen=(aSource.mLength<aDest.mLength) ? aDest.mLength : aSource.mLength;
aCount = (aCount<0) ? maxlen : MinInt(aCount,maxlen);
result=(*gCompare[aDest.mCharSize][aSource.mCharSize])(aDest.mStr,aSource.mStr,aCount,aIgnoreCase);
}
return result;
}
//----------------------------------------------------------------------------------------
PRBool nsStr::Alloc(nsStr& aDest,PRUint32 aCount) {
static int mAllocCount=0;
mAllocCount++;
//we're given the acount value in charunits; now scale up to next multiple.
PRUint32 theNewCapacity=kDefaultStringSize;
while(theNewCapacity<aCount){
theNewCapacity<<=1;
}
aDest.mCapacity=theNewCapacity++;
PRUint32 theSize=(theNewCapacity<<aDest.mCharSize);
aDest.mStr = (char*)nsAllocator::Alloc(theSize);
PRBool result=PR_FALSE;
if(aDest.mStr) {
aDest.mOwnsBuffer=1;
result=PR_TRUE;
}
return result;
}
PRBool nsStr::Free(nsStr& aDest){
if(aDest.mStr){
if(aDest.mOwnsBuffer){
nsAllocator::Free(aDest.mStr);
}
aDest.mStr=0;
aDest.mOwnsBuffer=0;
return PR_TRUE;
}
return PR_FALSE;
}
PRBool nsStr::Realloc(nsStr& aDest,PRUint32 aCount){
nsStr temp;
memcpy(&temp,&aDest,sizeof(aDest));
PRBool result=Alloc(temp,aCount);
if(result) {
Free(aDest);
aDest.mStr=temp.mStr;
aDest.mCapacity=temp.mCapacity;
aDest.mOwnsBuffer=temp.mOwnsBuffer;
}
return result;
}
//----------------------------------------------------------------------------------------
CBufDescriptor::CBufDescriptor(char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
mBuffer=aString;
mCharSize=eOneByte;
mStackBased=aStackBased;
mIsConst=PR_FALSE;
mLength=mCapacity=0;
if(aString && aCapacity>1) {
mCapacity=aCapacity-1;
mLength=(-1==aLength) ? strlen(aString) : aLength;
if(mLength>PRInt32(mCapacity))
mLength=mCapacity;
}
}
CBufDescriptor::CBufDescriptor(const char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
mBuffer=(char*)aString;
mCharSize=eOneByte;
mStackBased=aStackBased;
mIsConst=PR_TRUE;
mLength=mCapacity=0;
if(aString && aCapacity>1) {
mCapacity=aCapacity-1;
mLength=(-1==aLength) ? strlen(aString) : aLength;
if(mLength>PRInt32(mCapacity))
mLength=mCapacity;
}
}
CBufDescriptor::CBufDescriptor(PRUnichar* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
mBuffer=(char*)aString;
mCharSize=eTwoByte;
mStackBased=aStackBased;
mLength=mCapacity=0;
mIsConst=PR_FALSE;
if(aString && aCapacity>1) {
mCapacity=aCapacity-1;
mLength=(-1==aLength) ? nsCRT::strlen(aString) : aLength;
if(mLength>PRInt32(mCapacity))
mLength=mCapacity;
}
}
CBufDescriptor::CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
mBuffer=(char*)aString;
mCharSize=eTwoByte;
mStackBased=aStackBased;
mLength=mCapacity=0;
mIsConst=PR_TRUE;
if(aString && aCapacity>1) {
mCapacity=aCapacity-1;
mLength=(-1==aLength) ? nsCRT::strlen(aString) : aLength;
if(mLength>PRInt32(mCapacity))
mLength=mCapacity;
}
}
//----------------------------------------------------------------------------------------

View File

@@ -0,0 +1,450 @@
/* -*- 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.
*/
/***********************************************************************
MODULE NOTES:
1. There are two philosophies to building string classes:
A. Hide the underlying buffer & offer API's allow indirect iteration
B. Reveal underlying buffer, risk corruption, but gain performance
We chose the option B for performance reasons.
2 Our internal buffer always holds capacity+1 bytes.
The nsStr struct is a simple structure (no methods) that contains
the necessary info to be described as a string. This simple struct
is manipulated by the static methods provided in this class.
(Which effectively makes this a library that works on structs).
There are also object-based versions called nsString and nsAutoString
which use nsStr but makes it look at feel like an object.
***********************************************************************/
/***********************************************************************
ASSUMPTIONS:
1. nsStrings and nsAutoString are always null terminated.
2. If you try to set a null char (via SetChar()) a new length is set
3. nsCStrings can be upsampled into nsString without data loss
4. Char searching is faster than string searching. Use char interfaces
if your needs will allow it.
5. It's easy to use the stack for nsAutostring buffer storage (fast too!).
See the CBufDescriptor class in this file.
6. It's ONLY ok to provide non-null-terminated buffers to Append() and Insert()
provided you specify a 0<n value for the optional count argument.
7. Downsampling from nsString to nsCString is lossy -- avoid it if possible!
8. Calls to ToNewCString() and ToNewUnicode() should be matched with calls to Recycle().
***********************************************************************/
/**********************************************************************************
AND NOW FOR SOME GENERAL DOCUMENTATION ON STRING USAGE...
The fundamental datatype in the string library is nsStr. It's a structure that
provides the buffer storage and meta-info. It also provides a C-style library
of functions for direct manipulation (for those of you who prefer K&R to Bjarne).
Here's a diagram of the class hierarchy:
nsStr
|___nsString
| |
| ------nsAutoString
|
|___nsCString
|
------nsCAutoString
Why so many string classes? The 4 variants give you the control you need to
determine the best class for your purpose. There are 2 dimensions to this
flexibility: 1) stack vs. heap; and 2) 1-byte chars vs. 2-byte chars.
Note: While nsAutoString and nsCAutoString begin life using stack-based storage,
they may not stay that way. Like all nsString classes, autostrings will
automatically grow to contain the data you provide. When autostrings
grow beyond their intrinsic buffer, they switch to heap based allocations.
(We avoid alloca to avoid considerable platform difficulties; see the
GNU documentation for more details).
I should also briefly mention that all the string classes use a "memory agent"
object to perform memory operations. This class proxies the standard nsAllocator
for actual memory calls, but knows the structure of nsStr making heap operations
more localized.
CHOOSING A STRING CLASS:
In order to choose a string class for you purpose, use this handy table:
heap-based stack-based
-----------------------------------
ascii data | nsCString nsCAutoString |
|----------------------------------
unicode data | nsString nsAutoString |
-----------------------------------
Note: The i18n folks will stenuously object if we get too carried away with the
use of nsCString's that pass interface boundaries. Try to limit your
use of these to external interfaces that demand them, or for your own
private purposes in cases where they'll never be seen by humans.
PERFORMANCE CONSIDERATIONS:
Here are a few tricks to know in order to get better string performance:
1) Try to limit conversions between ascii and unicode; By sticking with nsString
wherever possible your code will be i18n-compliant.
2) Preallocating your string buffer cuts down trips to the allocator. So if you
have need for an arbitrarily large buffer, pre-size it like this:
{
nsString mBuffer;
mBuffer.SetCapacity(aReasonableSize);
}
3) Allocating nsAutoString or nsCAutoString on the heap is memory inefficient
(after all, the whole point is to avoid a heap allocation of the buffer).
4) Consider using an autoString to write into your arbitrarily-sized stack buffers, rather
than it's own buffers.
For example, let's say you're going to call printf() to emit pretty-printed debug output
of your object. You know from experience that the pretty-printed version of your object
exceeds the capacity of an autostring. Ignoring memory considerations, you could simply
use nsCString, appending the stringized version of each of your class's data members.
This will probably result in calls to the heap manager.
But there's a way to do this without necessarily having to call the heap manager.
All you do is declare a stack based buffer and instruct nsCString to use that instead
of it's own internal buffer by using the CBufDescriptor class:
{
char theBuffer[256];
CBufDescritor theBufDecriptor( theBuffer, PR_TRUE, sizeof(theBuffer), 0);
nsCAutoString s3( theBufDescriptor );
s3="HELLO, my name is inigo montoya, you killed my father, prepare to die!.";
}
The assignment statment to s3 will cause the given string to be written to your
stack-based buffer via the normal nsString/nsCString interfaces. Cool, huh?
Note however that just like any other nsStringXXX use, if you write more data
than will fit in the buffer, a visit to the heap manager will be in order.
**********************************************************************************/
#ifndef _nsStr
#define _nsStr
#include "nscore.h"
#include "nsIAllocator.h"
#include <string.h>
//----------------------------------------------------------------------------------------
enum eCharSize {eOneByte=0,eTwoByte=1};
#define kDefaultCharSize eTwoByte
#define kRadix10 (10)
#define kRadix16 (16)
#define kAutoDetect (100)
#define kRadixUnknown (kAutoDetect+1)
const PRInt32 kDefaultStringSize = 64;
const PRInt32 kNotFound = -1;
//----------------------------------------------------------------------------------------
class NS_COM CBufDescriptor {
public:
CBufDescriptor(char* aString, PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1);
CBufDescriptor(const char* aString, PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1);
CBufDescriptor(PRUnichar* aString, PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1);
CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1);
char* mBuffer;
eCharSize mCharSize;
PRUint32 mCapacity;
PRInt32 mLength;
PRBool mStackBased;
PRBool mIsConst;
};
//----------------------------------------------------------------------------------------
struct NS_COM nsStr {
//----------------------------------------------------------------------------------------
nsStr() {
MOZ_COUNT_CTOR(nsStr);
}
~nsStr() {
MOZ_COUNT_DTOR(nsStr);
}
/**
* This method initializes an nsStr for use
*
* @update gess 01/04/99
* @param aString is the nsStr to be initialized
* @param aCharSize tells us the requested char size (1 or 2 bytes)
*/
static void Initialize(nsStr& aDest,eCharSize aCharSize);
/**
* This method initializes an nsStr for use
*
* @update gess 01/04/99
* @param aString is the nsStr to be initialized
* @param aCharSize tells us the requested char size (1 or 2 bytes)
*/
static void Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer);
/**
* This method destroys the given nsStr, and *MAY*
* deallocate it's memory depending on the setting
* of the internal mOwnsBUffer flag.
*
* @update gess 01/04/99
* @param aString is the nsStr to be manipulated
* @param anAgent is the allocator to be used to the nsStr
*/
static void Destroy(nsStr& aDest);
/**
* These methods are where memory allocation/reallocation occur.
*
* @update gess 01/04/99
* @param aString is the nsStr to be manipulated
* @param anAgent is the allocator to be used on the nsStr
* @return
*/
static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength);
static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength);
/**
* These methods are used to append content to the given nsStr
*
* @update gess 01/04/99
* @param aDest is the nsStr to be appended to
* @param aSource is the buffer to be copied from
* @param anOffset tells us where in source to start copying
* @param aCount tells us the (max) # of chars to copy
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount);
/**
* These methods are used to assign contents of a source string to dest string
*
* @update gess 01/04/99
* @param aDest is the nsStr to be appended to
* @param aSource is the buffer to be copied from
* @param anOffset tells us where in source to start copying
* @param aCount tells us the (max) # of chars to copy
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount);
/**
* These methods are used to insert content from source string to the dest nsStr
*
* @update gess 01/04/99
* @param aDest is the nsStr to be appended to
* @param aDestOffset tells us where in dest to start insertion
* @param aSource is the buffer to be copied from
* @param aSrcOffset tells us where in source to start copying
* @param aCount tells us the (max) # of chars to insert
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount);
/**
* This method deletes chars from the given str.
* The given allocator may choose to resize the str as well.
*
* @update gess 01/04/99
* @param aDest is the nsStr to be deleted from
* @param aDestOffset tells us where in dest to start deleting
* @param aCount tells us the (max) # of chars to delete
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount);
/**
* This method is used to truncate the given string.
* The given allocator may choose to resize the str as well (but it's not likely).
*
* @update gess 01/04/99
* @param aDest is the nsStr to be appended to
* @param aDestOffset tells us where in dest to start insertion
* @param aSource is the buffer to be copied from
* @param aSrcOffset tells us where in source to start copying
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Truncate(nsStr& aDest,PRUint32 aDestOffset);
/**
* This method is used to perform a case conversion on the given string
*
* @update gess 01/04/99
* @param aDest is the nsStr to be case shifted
* @param toUpper tells us to go upper vs. lower
*/
static void ChangeCase(nsStr& aDest,PRBool aToUpper);
/**
* This method trims chars (given in aSet) from the edges of given buffer
*
* @update gess 01/04/99
* @param aDest is the buffer to be manipulated
* @param aSet tells us which chars to remove from given buffer
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
*/
static void Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
/**
* This method compresses duplicate runs of a given char from the given buffer
*
* @update gess 01/04/99
* @param aDest is the buffer to be manipulated
* @param aSet tells us which chars to compress from given buffer
* @param aChar is the replacement char
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
*/
static void CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
/**
* This method removes all occurances of chars in given set from aDest
*
* @update gess 01/04/99
* @param aDest is the buffer to be manipulated
* @param aSet tells us which chars to compress from given buffer
* @param aChar is the replacement char
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
*/
static void StripChars(nsStr& aDest,const char* aSet);
/**
* This method compares the data bewteen two nsStr's
*
* @update gess 01/04/99
* @param aStr1 is the first buffer to be compared
* @param aStr2 is the 2nd buffer to be compared
* @param aCount is the number of chars to compare
* @param aIgnorecase tells us whether to use a case-sensitive comparison
* @return -1,0,1 depending on <,==,>
*/
static PRInt32 Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase);
/**
* These methods scan the given string for 1 or more chars in a given direction
*
* @update gess 01/04/99
* @param aDest is the nsStr to be searched to
* @param aSource (or aChar) is the substr we're looking to find
* @param aIgnoreCase tells us whether to search in a case-sensitive manner
* @param anOffset tells us where in the dest string to start searching
* @return the index of the source (substr) in dest, or -1 (kNotFound) if not found.
*/
static PRInt32 FindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset);
static PRInt32 FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset);
static PRInt32 FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset);
static PRInt32 RFindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset);
static PRInt32 RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset);
static PRInt32 RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset);
PRUint32 mLength;
PRUint32 mCapacity;
eCharSize mCharSize;
PRBool mOwnsBuffer;
union {
char* mStr;
PRUnichar* mUStr;
};
private:
static PRBool Alloc(nsStr& aString,PRUint32 aCount);
static PRBool Realloc(nsStr& aString,PRUint32 aCount);
static PRBool Free(nsStr& aString);
};
/**************************************************************
A couple of tiny helper methods used in the string classes.
**************************************************************/
inline PRInt32 MinInt(PRInt32 anInt1,PRInt32 anInt2){
return (anInt1<anInt2) ? anInt1 : anInt2;
}
inline PRInt32 MaxInt(PRInt32 anInt1,PRInt32 anInt2){
return (anInt1<anInt2) ? anInt2 : anInt1;
}
inline void AddNullTerminator(nsStr& aDest) {
if(eTwoByte==aDest.mCharSize)
aDest.mUStr[aDest.mLength]=0;
else aDest.mStr[aDest.mLength]=0;
}
/**
* Return the given buffer to the heap manager. Calls allocator::Free()
* @return string length
*/
inline void Recycle( char* aBuffer) { nsAllocator::Free(aBuffer); }
inline void Recycle( PRUnichar* aBuffer) { nsAllocator::Free(aBuffer); }
/**
* This method is used to access a given char in the given string
*
* @update gess 01/04/99
* @param aDest is the nsStr to be appended to
* @param anIndex tells us where in dest to get the char from
* @return the given char, or 0 if anIndex is out of range
*/
inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex){
if(anIndex<aDest.mLength) {
return (eTwoByte==aDest.mCharSize) ? aDest.mUStr[anIndex] : aDest.mStr[anIndex];
}//if
return 0;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,747 @@
/* -*- 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.
*/
/***********************************************************************
MODULE NOTES:
See nsStr.h for a more general description of string classes.
This version of the nsString class offers many improvements over the
original version:
1. Wide and narrow chars
2. Allocators
3. Much smarter autostrings
4. Subsumable strings
***********************************************************************/
#ifndef _nsCString_
#define _nsCString_
#include "nsString2.h"
#include "prtypes.h"
#include "nscore.h"
#include <stdio.h>
#include "nsStr.h"
#include "nsIAtom.h"
class NS_COM nsSubsumeCStr;
class NS_COM nsCString : public nsStr {
public:
/**
* Default constructor.
*/
nsCString();
/**
* This constructor accepts an isolatin string
* @param aCString is a ptr to a 1-byte cstr
*/
nsCString(const char* aCString,PRInt32 aLength=-1);
/**
* This constructor accepts a unichar string
* @param aCString is a ptr to a 2-byte cstr
*/
nsCString(const PRUnichar* aString,PRInt32 aLength=-1);
/**
* This is a copy constructor that accepts an nsStr
* @param reference to another nsCString
*/
nsCString(const nsStr&);
/**
* This is our copy constructor
* @param reference to another nsCString
*/
nsCString(const nsCString& aString);
/**
* This constructor takes a subsumestr
* @param reference to subsumestr
*/
nsCString(nsSubsumeCStr& aSubsumeStr);
/**
* Destructor
*
*/
virtual ~nsCString();
/**
* Retrieve the length of this string
* @return string length
*/
inline PRInt32 Length() const { return (PRInt32)mLength; }
/**
* Retrieve the size of this string
* @return string length
*/
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
/**
* Call this method if you want to force a different string capacity
* @update gess7/30/98
* @param aLength -- contains new length for mStr
* @return
*/
void SetLength(PRUint32 aLength) {
Truncate(aLength);
}
/**
* Sets the new length of the string.
* @param aLength is new string length.
* @return nada
*/
void SetCapacity(PRUint32 aLength);
/**
* This method truncates this string to given length.
*
* @param anIndex -- new length of string
* @return nada
*/
void Truncate(PRInt32 anIndex=0);
/**
* Determine whether or not the characters in this
* string are in sorted order.
*
* @return TRUE if ordered.
*/
PRBool IsOrdered(void) const;
/**
* Determine whether or not this string has a length of 0
*
* @return TRUE if empty.
*/
PRBool IsEmpty(void) const {
return PRBool(0==mLength);
}
/**********************************************************************
Accessor methods...
*********************************************************************/
/**
* Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT!
*/
const char* GetBuffer(void) const;
/**
* Get nth character.
*/
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
/**********************************************************************
String creation methods...
*********************************************************************/
/**
* Create a new string by appending given string to this
* @param aString -- 2nd string to be appended
* @return new string
*/
nsSubsumeCStr operator+(const nsCString& aString);
/**
* create a new string by adding this to the given char*.
* @param aCString is a ptr to cstring to be added to this
* @return newly created string
*/
nsSubsumeCStr operator+(const char* aCString);
/**
* create a new string by adding this to the given char.
* @param aChar is a char to be added to this
* @return newly created string
*/
nsSubsumeCStr operator+(PRUnichar aChar);
nsSubsumeCStr operator+(char aChar);
/**********************************************************************
Lexomorphic transforms...
*********************************************************************/
/**
* Converts chars in this to lowercase
* @update gess 7/27/98
*/
void ToLowerCase();
/**
* Converts chars in this to lowercase, and
* stores them in aOut
* @update gess 7/27/98
* @param aOut is a string to contain result
*/
void ToLowerCase(nsCString& aString) const;
/**
* Converts chars in this to uppercase
* @update gess 7/27/98
*/
void ToUpperCase();
/**
* Converts chars in this to lowercase, and
* stores them in a given output string
* @update gess 7/27/98
* @param aOut is a string to contain result
*/
void ToUpperCase(nsCString& aString) const;
/**
* This method is used to remove all occurances of the
* characters found in aSet from this string.
*
* @param aSet -- characters to be cut from this
* @return *this
*/
nsCString& StripChars(const char* aSet);
nsCString& StripChar(char aChar);
/**
* This method strips whitespace throughout the string
*
* @return this
*/
nsCString& StripWhitespace();
/**
* swaps occurence of 1 string for another
*
* @return this
*/
nsCString& ReplaceChar(PRUnichar aOldChar,PRUnichar aNewChar);
nsCString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
PRInt32 CountChar(PRUnichar aChar);
/**
* This method trims characters found in aTrimSet from
* either end of the underlying string.
*
* @param aTrimSet -- contains chars to be trimmed from
* both ends
* @return this
*/
nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**
* This method strips whitespace from string.
* You can control whether whitespace is yanked from
* start and end of string as well.
*
* @param aEliminateLeading controls stripping of leading ws
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsCString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**
* This method strips whitespace from string.
* You can control whether whitespace is yanked from
* start and end of string as well.
*
* @param aEliminateLeading controls stripping of leading ws
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsCString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**********************************************************************
string conversion methods...
*********************************************************************/
operator char*() {return mStr;}
operator const char*() const {return (const char*)mStr;}
/**
* This method constructs a new nsCString that is a clone
* of this string.
*
*/
nsCString* ToNewString() const;
/**
* Creates an ISOLatin1 clone of this string
* Note that calls to this method should be matched with calls to Recycle().
* @return ptr to new isolatin1 string
*/
char* ToNewCString() const;
/**
* Creates a unicode clone of this string
* Note that calls to this method should be matched with calls to Recycle().
* @return ptr to new unicode string
*/
PRUnichar* ToNewUnicode() const;
/**
* Copies data from internal buffer onto given char* buffer
* NOTE: This only copies as many chars as will fit in given buffer (clips)
* @param aBuf is the buffer where data is stored
* @param aBuflength is the max # of chars to move to buffer
* @return ptr to given buffer
*/
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
/**
* Perform string to float conversion.
* @param aErrorCode will contain error if one occurs
* @return float rep of string value
*/
float ToFloat(PRInt32* aErrorCode) const;
/**
* Try to derive the radix from the value contained in this string
* @return kRadix10, kRadix16 or kAutoDetect (meaning unknown)
*/
PRUint32 DetermineRadix(void);
/**
* Perform string to int conversion.
* @param aErrorCode will contain error if one occurs
* @return int rep of string value
*/
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
/**********************************************************************
String manipulation methods...
*********************************************************************/
/**
* Functionally equivalent to assign or operator=
*
*/
nsCString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsCString& SetString(const nsStr& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
/**
* assign given string to this string
* @param aStr: buffer to be assigned to this
* @param alength is the length of the given str (or -1)
if you want me to determine its length
* @return this
*/
nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1);
nsCString& Assign(const char* aString,PRInt32 aCount=-1);
nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsCString& Assign(PRUnichar aChar);
nsCString& Assign(char aChar);
/**
* here come a bunch of assignment operators...
* @param aString: string to be added to this
* @return this
*/
nsCString& operator=(const nsCString& aString) {return Assign(aString);}
nsCString& operator=(const nsStr& aString) {return Assign(aString);}
nsCString& operator=(PRUnichar aChar) {return Assign(aChar);}
nsCString& operator=(char aChar) {return Assign(aChar);}
nsCString& operator=(const char* aCString) {return Assign(aCString);}
nsCString& operator=(const PRUnichar* aString) {return Assign(aString);}
#ifdef AIX
nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX requires a const here
#else
nsCString& operator=(nsSubsumeCStr& aSubsumeString);
#endif
/**
* Here's a bunch of methods that append varying types...
* @param various...
* @return this
*/
nsCString& operator+=(const nsCString& aString){return Append(aString,aString.mLength);}
nsCString& operator+=(const char* aCString) {return Append(aCString);}
nsCString& operator+=(PRUnichar aChar){return Append(aChar);}
nsCString& operator+=(char aChar){return Append(aChar);}
/*
* Appends n characters from given string to this,
* This version computes the length of your given string
*
* @param aString is the source to be appended to this
* @return number of chars copied
*/
nsCString& Append(const nsCString& aString) {return Append(aString,aString.mLength);}
/*
* Appends n characters from given string to this,
*
* @param aString is the source to be appended to this
* @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you
* @return number of chars copied
*/
nsCString& Append(const nsCString& aString,PRInt32 aCount);
nsCString& Append(const nsStr& aString,PRInt32 aCount=-1);
nsCString& Append(const char* aString,PRInt32 aCount=-1);
nsCString& Append(PRUnichar aChar);
nsCString& Append(char aChar);
nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
nsCString& Append(float aFloat);
/*
* Copies n characters from this string to given string,
* starting at the leftmost offset.
*
*
* @param aCopy -- Receiving string
* @param aCount -- number of chars to copy
* @return number of chars copied
*/
PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const;
/*
* Copies n characters from this string to given string,
* starting at the given offset.
*
*
* @param aCopy -- Receiving string
* @param aCount -- number of chars to copy
* @param anOffset -- position where copying begins
* @return number of chars copied
*/
PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
/*
* Copies n characters from this string to given string,
* starting at rightmost char.
*
*
* @param aCopy -- Receiving string
* @param aCount -- number of chars to copy
* @return number of chars copied
*/
PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const;
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
* @param aCopy -- String to be inserted into this
* @param anOffset -- insertion position within this str
* @param aCount -- number of chars to be copied from aCopy
* @return number of chars inserted into this.
*/
nsCString& Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
/**
* Insert a given string into this string at
* a specified offset.
*
* @param aString* to be inserted into this string
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
nsCString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
/**
* Insert a single char into this string at
* a specified offset.
*
* @param character to be inserted into this string
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
nsCString& Insert(PRUnichar aChar,PRUint32 anOffset);
nsCString& Insert(char aChar,PRUint32 anOffset);
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
* @param anOffset -- start pos for cut operation
* @param aCount -- number of chars to be cut
* @return *this
*/
nsCString& Cut(PRUint32 anOffset,PRInt32 aCount);
/**********************************************************************
Searching methods...
*********************************************************************/
/**
* Search for given character within this string.
* This method does so by using a binary search,
* so your string HAD BETTER BE ORDERED!
*
* @param aChar is the unicode char to be found
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 BinarySearch(PRUnichar aChar) const;
/**
* Search for given substring within this string
*
* @param aString is substring to be sought in this
* @param aIgnoreCase selects case sensitivity
* @param anOffset tells us where in this strig to start searching
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
* @param anOffset tells us where in this strig to start searching
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
* This method searches this string for the first character
* found in the given charset
* @param aString contains set of chars to be found
* @param anOffset tells us where to start searching in this
* @return -1 if not found, else the offset in this
*/
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
/**
* This methods scans the string backwards, looking for the given string
* @param aString is substring to be sought in this
* @param aIgnoreCase tells us whether or not to do caseless compare
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
* @param anOffset tells us where in this strig to start searching
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
* This method searches this string for the last character
* found in the given string
* @param aString contains set of chars to be found
* @param anOffset tells us where to start searching in this
* @return -1 if not found, else the offset in this
*/
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
/**********************************************************************
Comparison methods...
*********************************************************************/
/**
* Compares a given string type to this string.
* @update gess 7/27/98
* @param S is the string to be compared
* @param aIgnoreCase tells us how to treat case
* @param aCount tells us how many chars to compare
* @return -1,0,1
*/
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
/**
* These methods compare a given string type to this one
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char* aString) const;
PRBool operator==(const PRUnichar* aString) const;
/**
* These methods perform a !compare of a given string type to this
* @param aString is the string to be compared to this
* @return TRUE
*/
PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const;
/**
* These methods test if a given string is < than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const;
/**
* These methods test if a given string is > than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const;
/**
* These methods test if a given string is <= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const;
/**
* These methods test if a given string is >= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const;
/**
* Compare this to given string; note that we compare full strings here.
* The optional length argument just lets us know how long the given string is.
* If you provide a length, it is compared to length of this string as an
* optimization.
*
* @param aString -- the string to compare to this
* @param aCount -- number of chars in given string you want to compare
* @return TRUE if equal
*/
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const nsStr& aString) const;
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const;
static void Recycle(nsCString* aString);
static nsCString* CreateString(void);
};
extern NS_COM int fputs(const nsCString& aString, FILE* out);
//ostream& operator<<(ostream& aStream,const nsCString& aString);
//virtual void DebugDump(ostream& aStream) const;
/**************************************************************
Here comes the AutoString class which uses internal memory
(typically found on the stack) for its default buffer.
If the buffer needs to grow, it gets reallocated on the heap.
**************************************************************/
class NS_COM nsCAutoString : public nsCString {
public:
nsCAutoString();
nsCAutoString(const char* aString,PRInt32 aLength=-1);
nsCAutoString(const CBufDescriptor& aBuffer);
nsCAutoString(const PRUnichar* aString,PRInt32 aLength=-1);
nsCAutoString(const nsStr& aString);
nsCAutoString(const nsCAutoString& aString);
#ifdef AIX
nsCAutoString(const nsSubsumeCStr& aSubsumeStr); // AIX requires a const
#else
nsCAutoString(nsSubsumeCStr& aSubsumeStr);
#endif // AIX
nsCAutoString(PRUnichar aChar);
virtual ~nsCAutoString();
nsCAutoString& operator=(const nsCString& aString) {nsCString::Assign(aString); return *this;}
nsCAutoString& operator=(const char* aCString) {nsCString::Assign(aCString); return *this;}
nsCAutoString& operator=(PRUnichar aChar) {nsCString::Assign(aChar); return *this;}
nsCAutoString& operator=(char aChar) {nsCString::Assign(aChar); return *this;}
/**
* Retrieve the size of this string
* @return string length
*/
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
char mBuffer[kDefaultStringSize];
};
/***************************************************************
The subsumestr class is very unusual.
It differs from a normal string in that it doesn't use normal
copy semantics when another string is assign to this.
Instead, it "steals" the contents of the source string.
This is very handy for returning nsString classes as part of
an operator+(...) for example, in that it cuts down the number
of copy operations that must occur.
You should probably not use this class unless you really know
what you're doing.
***************************************************************/
class NS_COM nsSubsumeCStr : public nsCString {
public:
nsSubsumeCStr(nsStr& aString);
nsSubsumeCStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
nsSubsumeCStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
};
#endif

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More