2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsTitleBarFrame.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMNodeList.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIWidget.h"
|
2007-04-20 03:56:49 -07:00
|
|
|
#include "nsMenuPopupFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsPresContext.h"
|
2007-04-20 03:56:49 -07:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsEventDispatcher.h"
|
|
|
|
#include "nsDisplayList.h"
|
2009-06-30 00:56:40 -07:00
|
|
|
#include "nsContentUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// NS_NewTitleBarFrame
|
|
|
|
//
|
|
|
|
// Creates a new TitleBar frame and returns it
|
|
|
|
//
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewTitleBarFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsTitleBarFrame(aPresShell, aContext);
|
2009-09-12 09:49:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsTitleBarFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsTitleBarFrame::nsTitleBarFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2011-10-17 07:59:28 -07:00
|
|
|
:nsBoxFrame(aPresShell, aContext, false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mTrackingMouseMove = false;
|
2010-11-30 06:59:46 -08:00
|
|
|
UpdateMouseThrough();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTitleBarFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
// override, since we don't want children to get events
|
|
|
|
if (aBuilder->IsForEventDelivery()) {
|
2008-04-21 09:53:30 -07:00
|
|
|
if (!mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::allowevents,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGkAtoms::_true, eCaseMatters))
|
2013-02-14 03:12:27 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-02-14 03:12:27 -08:00
|
|
|
nsBoxFrame::BuildDisplayListForChildren(aBuilder, aDirtyRect, aLists);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
|
|
|
{
|
2009-02-27 02:48:25 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool doDefault = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch (aEvent->message) {
|
|
|
|
|
|
|
|
case NS_MOUSE_BUTTON_DOWN: {
|
|
|
|
if (aEvent->eventStructType == NS_MOUSE_EVENT &&
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsMouseEvent*>(aEvent)->button ==
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMouseEvent::eLeftButton)
|
|
|
|
{
|
2007-04-20 03:56:49 -07:00
|
|
|
// titlebar has no effect in non-chrome shells
|
|
|
|
nsCOMPtr<nsISupports> cont = aPresContext->GetContainer();
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(cont);
|
|
|
|
if (dsti) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t type = -1;
|
2007-04-20 03:56:49 -07:00
|
|
|
if (NS_SUCCEEDED(dsti->GetItemType(&type)) &&
|
|
|
|
type == nsIDocShellTreeItem::typeChrome) {
|
|
|
|
// we're tracking.
|
2011-10-17 07:59:28 -07:00
|
|
|
mTrackingMouseMove = true;
|
2007-04-20 03:56:49 -07:00
|
|
|
|
|
|
|
// start capture.
|
2009-09-13 06:13:16 -07:00
|
|
|
nsIPresShell::SetCapturingContent(GetContent(), CAPTURE_IGNOREALLOWED);
|
2007-04-20 03:56:49 -07:00
|
|
|
|
|
|
|
// remember current mouse coordinates.
|
|
|
|
mLastPoint = aEvent->refPoint;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
2011-10-17 07:59:28 -07:00
|
|
|
doDefault = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case NS_MOUSE_BUTTON_UP: {
|
|
|
|
if(mTrackingMouseMove && aEvent->eventStructType == NS_MOUSE_EVENT &&
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsMouseEvent*>(aEvent)->button ==
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMouseEvent::eLeftButton)
|
|
|
|
{
|
|
|
|
// we're done tracking.
|
2011-10-17 07:59:28 -07:00
|
|
|
mTrackingMouseMove = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// end capture
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIPresShell::SetCapturingContent(nullptr, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
2011-10-17 07:59:28 -07:00
|
|
|
doDefault = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_MOUSE_MOVE: {
|
|
|
|
if(mTrackingMouseMove)
|
|
|
|
{
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntPoint nsMoveBy = aEvent->refPoint - mLastPoint;
|
2007-04-20 03:56:49 -07:00
|
|
|
|
|
|
|
nsIFrame* parent = GetParent();
|
2012-07-30 17:43:28 -07:00
|
|
|
while (parent) {
|
|
|
|
nsMenuPopupFrame* popupFrame = do_QueryFrame(parent);
|
|
|
|
if (popupFrame)
|
|
|
|
break;
|
2007-04-20 03:56:49 -07:00
|
|
|
parent = parent->GetParent();
|
2012-07-30 17:43:28 -07:00
|
|
|
}
|
2007-04-20 03:56:49 -07:00
|
|
|
|
2010-02-01 07:11:08 -08:00
|
|
|
// if the titlebar is in a popup, move the popup frame, otherwise
|
2007-04-20 03:56:49 -07:00
|
|
|
// move the widget associated with the window
|
|
|
|
if (parent) {
|
2010-02-01 07:11:08 -08:00
|
|
|
nsMenuPopupFrame* menuPopupFrame = static_cast<nsMenuPopupFrame*>(parent);
|
2011-12-01 13:35:42 -08:00
|
|
|
nsCOMPtr<nsIWidget> widget = menuPopupFrame->GetWidget();
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntRect bounds;
|
2007-04-20 03:56:49 -07:00
|
|
|
widget->GetScreenBounds(bounds);
|
2011-10-17 07:59:28 -07:00
|
|
|
menuPopupFrame->MoveTo(bounds.x + nsMoveBy.x, bounds.y + nsMoveBy.y, false);
|
2007-04-20 03:56:49 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIPresShell* presShell = aPresContext->PresShell();
|
|
|
|
nsPIDOMWindow *window = presShell->GetDocument()->GetWindow();
|
2008-09-28 12:14:28 -07:00
|
|
|
if (window) {
|
|
|
|
window->MoveBy(nsMoveBy.x, nsMoveBy.y);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
doDefault = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case NS_MOUSE_CLICK:
|
|
|
|
if (NS_IS_MOUSE_LEFT_CLICK(aEvent))
|
|
|
|
{
|
|
|
|
MouseClicked(aPresContext, aEvent);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( doDefault )
|
|
|
|
return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
else
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTitleBarFrame::MouseClicked(nsPresContext* aPresContext, nsGUIEvent* aEvent)
|
|
|
|
{
|
|
|
|
// Execute the oncommand event handler.
|
2009-06-30 00:56:40 -07:00
|
|
|
nsContentUtils::DispatchXULCommand(mContent,
|
2012-12-15 17:26:03 -08:00
|
|
|
aEvent && aEvent->mFlags.mIsTrusted);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|