|
|
|
|
| 54 |
#include "nsCOMPtr.h" |
54 |
#include "nsCOMPtr.h" |
| 55 |
#include "nsIEventQueue.h" |
55 |
#include "nsIEventQueue.h" |
| 56 |
#include "nsIEventQueueService.h" |
56 |
#include "nsIEventQueueService.h" |
| 57 |
#include "nsIServiceManager.h" |
57 |
#include "nsIServiceManager.h" |
| 58 |
#include "nsGUIEvent.h" |
58 |
#include "nsGUIEvent.h" |
| 59 |
#include "nsIPrefBranch.h" |
59 |
#include "nsIPrefBranch.h" |
| 60 |
#include "nsIPrefService.h" |
60 |
#include "nsIPrefService.h" |
| 61 |
#include "nsRegion.h" |
61 |
#include "nsRegion.h" |
| 62 |
#include "nsInt64.h" |
62 |
#include "nsInt64.h" |
| 63 |
#include "nsScrollPortView.h" |
63 |
#include "nsScrollPortView.h" |
| 64 |
#include "nsHashtable.h" |
64 |
#include "nsHashtable.h" |
| 65 |
|
65 |
|
|
|
66 |
// XXX Hack |
| 67 |
#include "nsIPresShell.h" |
| 68 |
#include "nsIBaseWindow.h" |
| 69 |
#include "nsPresContext.h" |
| 70 |
|
| 66 |
static NS_DEFINE_IID(kBlenderCID, NS_BLENDER_CID); |
71 |
static NS_DEFINE_IID(kBlenderCID, NS_BLENDER_CID); |
| 67 |
static NS_DEFINE_IID(kRegionCID, NS_REGION_CID); |
72 |
static NS_DEFINE_IID(kRegionCID, NS_REGION_CID); |
| 68 |
static NS_DEFINE_IID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID); |
73 |
static NS_DEFINE_IID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID); |
| 69 |
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); |
74 |
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); |
| 70 |
|
75 |
|
| 71 |
#define ARENA_ALLOCATE(var, pool, type) \ |
76 |
#define ARENA_ALLOCATE(var, pool, type) \ |
| 72 |
{void *_tmp_; PL_ARENA_ALLOCATE(_tmp_, pool, sizeof(type)); \ |
77 |
{void *_tmp_; PL_ARENA_ALLOCATE(_tmp_, pool, sizeof(type)); \ |
| 73 |
var = NS_REINTERPRET_CAST(type*, _tmp_); } |
78 |
var = NS_REINTERPRET_CAST(type*, _tmp_); } |
| 74 |
/** |
79 |
/** |
| 75 |
XXX TODO XXX |
80 |
XXX TODO XXX |
| 76 |
|
81 |
|
| 77 |
DeCOMify newly private methods |
82 |
DeCOMify newly private methods |
|
Lines 403-426
static PRInt32 CompareZIndex(PRInt32 aZI
|
Link Here
|
|---|
|
| 403 |
PRInt32 aZIndex2, PRBool aTopMost2, PRBool aIsAuto2) |
408 |
PRInt32 aZIndex2, PRBool aTopMost2, PRBool aIsAuto2) |
| 404 |
{ |
409 |
{ |
| 405 |
NS_ASSERTION(!aIsAuto1 || aZIndex1 == 0,"auto is set and the z-index is not 0"); |
410 |
NS_ASSERTION(!aIsAuto1 || aZIndex1 == 0,"auto is set and the z-index is not 0"); |
| 406 |
NS_ASSERTION(!aIsAuto2 || aZIndex2 == 0,"auto is set and the z-index is not 0"); |
411 |
NS_ASSERTION(!aIsAuto2 || aZIndex2 == 0,"auto is set and the z-index is not 0"); |
| 407 |
|
412 |
|
| 408 |
if (aZIndex1 != aZIndex2) { |
413 |
if (aZIndex1 != aZIndex2) { |
| 409 |
return aZIndex1 - aZIndex2; |
414 |
return aZIndex1 - aZIndex2; |
| 410 |
} else { |
415 |
} else { |
| 411 |
return aTopMost1 - aTopMost2; |
416 |
return aTopMost1 - aTopMost2; |
| 412 |
} |
417 |
} |
| 413 |
} |
418 |
} |
| 414 |
|
419 |
|
|
|
420 |
static PRBool IsViewVisible(nsView *aView) |
| 421 |
{ |
| 422 |
for (nsIView *view = aView; view; view = view->GetParent()) { |
| 423 |
if (view->GetVisibility() == nsViewVisibility_kHide) |
| 424 |
return PR_FALSE; |
| 425 |
#if 0 |
| 426 |
if (view->HasWidget()) { |
| 427 |
PRBool visible = PR_TRUE; |
| 428 |
view->GetWidget()->IsVisible(visible); |
| 429 |
if (!visible) |
| 430 |
return PR_FALSE; |
| 431 |
} |
| 432 |
#endif |
| 433 |
} |
| 434 |
// Find out if the root view is visible by asking the docshell (this |
| 435 |
// won't be needed anymore if we link view trees across chrome / content |
| 436 |
// boundaries. |
| 437 |
nsCOMPtr<nsIViewObserver> vo; |
| 438 |
aView->GetViewManager()->GetViewObserver(*getter_AddRefs(vo)); |
| 439 |
nsCOMPtr<nsIPresShell> shell = do_QueryInterface(vo); |
| 440 |
if (!shell) |
| 441 |
return PR_FALSE; |
| 442 |
nsCOMPtr<nsISupports> container = shell->GetPresContext()->GetContainer(); |
| 443 |
nsCOMPtr<nsIBaseWindow> bw = do_QueryInterface(container); |
| 444 |
if (!bw) |
| 445 |
return PR_FALSE; |
| 446 |
PRBool res = PR_TRUE; |
| 447 |
bw->GetVisibility(&res); |
| 448 |
return res; |
| 449 |
} |
| 450 |
|
| 415 |
void |
451 |
void |
| 416 |
nsViewManager::PostInvalidateEvent() |
452 |
nsViewManager::PostInvalidateEvent() |
| 417 |
{ |
453 |
{ |
| 418 |
nsCOMPtr<nsIEventQueue> eventQueue; |
454 |
nsCOMPtr<nsIEventQueue> eventQueue; |
| 419 |
mEventQueueService->GetSpecialEventQueue( |
455 |
mEventQueueService->GetSpecialEventQueue( |
| 420 |
nsIEventQueueService::UI_THREAD_EVENT_QUEUE, getter_AddRefs(eventQueue)); |
456 |
nsIEventQueueService::UI_THREAD_EVENT_QUEUE, getter_AddRefs(eventQueue)); |
| 421 |
NS_ASSERTION(nsnull != eventQueue, "Event queue is null"); |
457 |
NS_ASSERTION(nsnull != eventQueue, "Event queue is null"); |
| 422 |
|
458 |
|
| 423 |
if (eventQueue != mInvalidateEventQueue) { |
459 |
if (eventQueue != mInvalidateEventQueue) { |
| 424 |
nsInvalidateEvent* ev = new nsInvalidateEvent(this); |
460 |
nsInvalidateEvent* ev = new nsInvalidateEvent(this); |
| 425 |
eventQueue->PostEvent(ev); |
461 |
eventQueue->PostEvent(ev); |
| 426 |
mInvalidateEventQueue = eventQueue; |
462 |
mInvalidateEventQueue = eventQueue; |
|
Lines 429-452
nsViewManager::PostInvalidateEvent()
|
Link Here
|
|---|
|
| 429 |
|
465 |
|
| 430 |
#undef DEBUG_MOUSE_LOCATION |
466 |
#undef DEBUG_MOUSE_LOCATION |
| 431 |
|
467 |
|
| 432 |
PRInt32 nsViewManager::mVMCount = 0; |
468 |
PRInt32 nsViewManager::mVMCount = 0; |
| 433 |
nsIRenderingContext* nsViewManager::gCleanupContext = nsnull; |
469 |
nsIRenderingContext* nsViewManager::gCleanupContext = nsnull; |
| 434 |
|
470 |
|
| 435 |
// Weakly held references to all of the view managers |
471 |
// Weakly held references to all of the view managers |
| 436 |
nsVoidArray* nsViewManager::gViewManagers = nsnull; |
472 |
nsVoidArray* nsViewManager::gViewManagers = nsnull; |
| 437 |
PRUint32 nsViewManager::gLastUserEventTime = 0; |
473 |
PRUint32 nsViewManager::gLastUserEventTime = 0; |
| 438 |
|
474 |
|
| 439 |
nsViewManager::nsViewManager() |
475 |
nsViewManager::nsViewManager() |
| 440 |
: mMouseLocation(NSCOORD_NONE, NSCOORD_NONE) |
476 |
: mMouseLocation(NSCOORD_NONE, NSCOORD_NONE) |
|
|
477 |
, mDelayedResize(NSCOORD_NONE, NSCOORD_NONE) |
| 441 |
{ |
478 |
{ |
| 442 |
if (gViewManagers == nsnull) { |
479 |
if (gViewManagers == nsnull) { |
| 443 |
NS_ASSERTION(mVMCount == 0, "View Manager count is incorrect"); |
480 |
NS_ASSERTION(mVMCount == 0, "View Manager count is incorrect"); |
| 444 |
// Create an array to hold a list of view managers |
481 |
// Create an array to hold a list of view managers |
| 445 |
gViewManagers = new nsVoidArray; |
482 |
gViewManagers = new nsVoidArray; |
| 446 |
} |
483 |
} |
| 447 |
|
484 |
|
| 448 |
if (gCleanupContext == nsnull) { |
485 |
if (gCleanupContext == nsnull) { |
| 449 |
/* XXX: This should use a device to create a matching |nsIRenderingContext| object */ |
486 |
/* XXX: This should use a device to create a matching |nsIRenderingContext| object */ |
| 450 |
CallCreateInstance(kRenderingContextCID, &gCleanupContext); |
487 |
CallCreateInstance(kRenderingContextCID, &gCleanupContext); |
| 451 |
NS_ASSERTION(gCleanupContext, |
488 |
NS_ASSERTION(gCleanupContext, |
| 452 |
"Wasn't able to create a graphics context for cleanup"); |
489 |
"Wasn't able to create a graphics context for cleanup"); |
|
Lines 605-655
NS_IMETHODIMP nsViewManager::SetRootView
|
Link Here
|
|---|
|
| 605 |
parent->InsertChild(mRootView, nsnull); |
642 |
parent->InsertChild(mRootView, nsnull); |
| 606 |
} |
643 |
} |
| 607 |
|
644 |
|
| 608 |
mRootView->SetZIndex(PR_FALSE, 0, PR_FALSE); |
645 |
mRootView->SetZIndex(PR_FALSE, 0, PR_FALSE); |
| 609 |
} |
646 |
} |
| 610 |
|
647 |
|
| 611 |
return NS_OK; |
648 |
return NS_OK; |
| 612 |
} |
649 |
} |
| 613 |
|
650 |
|
| 614 |
NS_IMETHODIMP nsViewManager::GetWindowDimensions(nscoord *aWidth, nscoord *aHeight) |
651 |
NS_IMETHODIMP nsViewManager::GetWindowDimensions(nscoord *aWidth, nscoord *aHeight) |
| 615 |
{ |
652 |
{ |
| 616 |
if (nsnull != mRootView) { |
653 |
if (nsnull != mRootView) { |
| 617 |
nsRect dim; |
654 |
if (mDelayedResize == nsSize(NSCOORD_NONE, NSCOORD_NONE)) { |
| 618 |
mRootView->GetDimensions(dim); |
655 |
nsRect dim; |
| 619 |
*aWidth = dim.width; |
656 |
mRootView->GetDimensions(dim); |
| 620 |
*aHeight = dim.height; |
657 |
*aWidth = dim.width; |
|
|
658 |
*aHeight = dim.height; |
| 659 |
} else { |
| 660 |
*aWidth = mDelayedResize.width; |
| 661 |
*aHeight = mDelayedResize.height; |
| 662 |
} |
| 621 |
} |
663 |
} |
| 622 |
else |
664 |
else |
| 623 |
{ |
665 |
{ |
| 624 |
*aWidth = 0; |
666 |
*aWidth = 0; |
| 625 |
*aHeight = 0; |
667 |
*aHeight = 0; |
| 626 |
} |
668 |
} |
| 627 |
return NS_OK; |
669 |
return NS_OK; |
| 628 |
} |
670 |
} |
| 629 |
|
671 |
|
| 630 |
NS_IMETHODIMP nsViewManager::SetWindowDimensions(nscoord aWidth, nscoord aHeight) |
672 |
NS_IMETHODIMP nsViewManager::SetWindowDimensions(nscoord aWidth, nscoord aHeight) |
| 631 |
{ |
673 |
{ |
| 632 |
// Resize the root view |
674 |
if (mRootView) { |
| 633 |
if (nsnull != mRootView) { |
675 |
if (IsViewVisible(mRootView) || mRootView->GetDimensions().IsEmpty()) { |
| 634 |
nsRect dim(0, 0, aWidth, aHeight); |
676 |
DoSetWindowDimensions(aWidth, aHeight); |
| 635 |
mRootView->SetDimensions(dim); |
677 |
} else { |
|
|
678 |
mDelayedResize.SizeTo(aWidth, aHeight); |
| 679 |
} |
| 636 |
} |
680 |
} |
| 637 |
|
681 |
|
| 638 |
//printf("new dims: %d %d\n", aWidth, aHeight); |
|
|
| 639 |
// Inform the presentation shell that we've been resized |
| 640 |
if (nsnull != mObserver) |
| 641 |
mObserver->ResizeReflow(mRootView, aWidth, aHeight); |
| 642 |
//printf("reflow done\n"); |
| 643 |
|
| 644 |
return NS_OK; |
682 |
return NS_OK; |
| 645 |
} |
683 |
} |
| 646 |
|
684 |
|
| 647 |
NS_IMETHODIMP nsViewManager::ResetScrolling(void) |
685 |
NS_IMETHODIMP nsViewManager::ResetScrolling(void) |
| 648 |
{ |
686 |
{ |
| 649 |
if (nsnull != mRootScrollable) |
687 |
if (nsnull != mRootScrollable) |
| 650 |
mRootScrollable->ComputeScrollOffsets(PR_TRUE); |
688 |
mRootScrollable->ComputeScrollOffsets(PR_TRUE); |
| 651 |
|
689 |
|
| 652 |
return NS_OK; |
690 |
return NS_OK; |
| 653 |
} |
691 |
} |
| 654 |
|
692 |
|
| 655 |
/* Check the prefs to see whether we should do double buffering or not... */ |
693 |
/* Check the prefs to see whether we should do double buffering or not... */ |
|
Lines 1825-1848
NS_IMETHODIMP nsViewManager::DispatchEve
|
Link Here
|
|---|
|
| 1825 |
if (NS_FAILED(CreateRegion(getter_AddRefs(region)))) |
1863 |
if (NS_FAILED(CreateRegion(getter_AddRefs(region)))) |
| 1826 |
break; |
1864 |
break; |
| 1827 |
|
1865 |
|
| 1828 |
const nsRect& damrect = *((nsPaintEvent*)aEvent)->rect; |
1866 |
const nsRect& damrect = *((nsPaintEvent*)aEvent)->rect; |
| 1829 |
region->SetTo(damrect.x, damrect.y, damrect.width, damrect.height); |
1867 |
region->SetTo(damrect.x, damrect.y, damrect.width, damrect.height); |
| 1830 |
} |
1868 |
} |
| 1831 |
|
1869 |
|
| 1832 |
if (region->IsEmpty()) |
1870 |
if (region->IsEmpty()) |
| 1833 |
break; |
1871 |
break; |
| 1834 |
|
1872 |
|
| 1835 |
// Refresh the view |
1873 |
// Refresh the view |
| 1836 |
if (mRefreshEnabled) { |
1874 |
if (mRefreshEnabled) { |
|
|
1875 |
// If an ancestor widget was hidden and then shown, we could |
| 1876 |
// have a delayed resize to handle. |
| 1877 |
if (view == mRootView && |
| 1878 |
mDelayedResize != nsSize(NSCOORD_NONE, NSCOORD_NONE) && |
| 1879 |
IsViewVisible(view)) { |
| 1880 |
DoSetWindowDimensions(mDelayedResize.width, mDelayedResize.height); |
| 1881 |
mDelayedResize.SizeTo(NSCOORD_NONE, NSCOORD_NONE); |
| 1882 |
} |
| 1883 |
|
| 1837 |
Refresh(view, ((nsPaintEvent*)aEvent)->renderingContext, region, |
1884 |
Refresh(view, ((nsPaintEvent*)aEvent)->renderingContext, region, |
| 1838 |
NS_VMREFRESH_DOUBLE_BUFFER); |
1885 |
NS_VMREFRESH_DOUBLE_BUFFER); |
| 1839 |
} else { |
1886 |
} else { |
| 1840 |
// since we got an NS_PAINT event, we need to |
1887 |
// since we got an NS_PAINT event, we need to |
| 1841 |
// draw something so we don't get blank areas. |
1888 |
// draw something so we don't get blank areas. |
| 1842 |
nsRect damRect; |
1889 |
nsRect damRect; |
| 1843 |
region->GetBoundingBox(&damRect.x, &damRect.y, &damRect.width, &damRect.height); |
1890 |
region->GetBoundingBox(&damRect.x, &damRect.y, &damRect.width, &damRect.height); |
| 1844 |
float p2t; |
1891 |
float p2t; |
| 1845 |
p2t = mContext->DevUnitsToAppUnits(); |
1892 |
p2t = mContext->DevUnitsToAppUnits(); |
| 1846 |
damRect.ScaleRoundOut(p2t); |
1893 |
damRect.ScaleRoundOut(p2t); |
| 1847 |
DefaultRefresh(view, &damRect); |
1894 |
DefaultRefresh(view, &damRect); |
| 1848 |
|
1895 |
|