2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2000-07-12 03:37:00 +04:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsTitleBarFrame.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMNodeList.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2000-07-12 03:37:00 +04:00
|
|
|
#include "nsIWidget.h"
|
2007-04-20 14:56:49 +04:00
|
|
|
#include "nsMenuPopupFrame.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2013-11-20 23:18:25 +04:00
|
|
|
#include "nsIDocShell.h"
|
2005-11-29 02:56:44 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2009-06-30 11:56:40 +04:00
|
|
|
#include "nsContentUtils.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2000-07-12 03:37:00 +04:00
|
|
|
|
2013-08-02 11:05:16 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2000-07-12 03:37:00 +04:00
|
|
|
//
|
|
|
|
// NS_NewTitleBarFrame
|
|
|
|
//
|
2005-10-27 01:46:39 +04:00
|
|
|
// Creates a new TitleBar frame and returns it
|
2000-07-12 03:37:00 +04:00
|
|
|
//
|
2005-10-27 01:46:39 +04:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewTitleBarFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2000-07-12 03:37:00 +04:00
|
|
|
{
|
2015-01-06 12:27:56 +03:00
|
|
|
return new (aPresShell) nsTitleBarFrame(aContext);
|
2009-09-12 20:49:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsTitleBarFrame)
|
2000-07-12 03:37:00 +04:00
|
|
|
|
2015-01-06 12:27:56 +03:00
|
|
|
nsTitleBarFrame::nsTitleBarFrame(nsStyleContext* aContext)
|
|
|
|
:nsBoxFrame(aContext, false)
|
2000-07-12 03:37:00 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mTrackingMouseMove = false;
|
2010-11-30 17:59:46 +03:00
|
|
|
UpdateMouseThrough();
|
2000-07-12 03:37:00 +04:00
|
|
|
}
|
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
void
|
2006-01-26 05:29:17 +03:00
|
|
|
nsTitleBarFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
2000-07-12 03:37:00 +04:00
|
|
|
{
|
|
|
|
// override, since we don't want children to get events
|
2006-11-22 00:04:49 +03:00
|
|
|
if (aBuilder->IsForEventDelivery()) {
|
2008-04-21 20:53:30 +04:00
|
|
|
if (!mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::allowevents,
|
2006-12-26 20:47:52 +03:00
|
|
|
nsGkAtoms::_true, eCaseMatters))
|
2013-02-14 15:12:27 +04:00
|
|
|
return;
|
2006-11-22 00:04:49 +03:00
|
|
|
}
|
2013-02-14 15:12:27 +04:00
|
|
|
nsBoxFrame::BuildDisplayListForChildren(aBuilder, aDirtyRect, aLists);
|
2000-07-12 03:37:00 +04:00
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2005-11-29 02:56:44 +03:00
|
|
|
nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext,
|
2013-10-02 07:46:03 +04:00
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
2000-07-12 03:37:00 +04:00
|
|
|
{
|
2009-02-27 13:48:25 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-07-12 03:37:00 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool doDefault = true;
|
2000-07-12 03:37:00 +04:00
|
|
|
|
2015-08-22 04:34:51 +03:00
|
|
|
switch (aEvent->mMessage) {
|
2000-07-12 03:37:00 +04:00
|
|
|
|
2006-11-17 00:35:39 +03:00
|
|
|
case NS_MOUSE_BUTTON_DOWN: {
|
2013-10-22 12:55:20 +04:00
|
|
|
if (aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) {
|
2007-04-20 14:56:49 +04:00
|
|
|
// titlebar has no effect in non-chrome shells
|
2013-11-20 23:18:25 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> dsti = aPresContext->GetDocShell();
|
2007-04-20 14:56:49 +04:00
|
|
|
if (dsti) {
|
2014-01-20 11:58:26 +04:00
|
|
|
if (dsti->ItemType() == nsIDocShellTreeItem::typeChrome) {
|
2007-04-20 14:56:49 +04:00
|
|
|
// we're tracking.
|
2011-10-17 18:59:28 +04:00
|
|
|
mTrackingMouseMove = true;
|
2007-04-20 14:56:49 +04:00
|
|
|
|
|
|
|
// start capture.
|
2009-09-13 17:13:16 +04:00
|
|
|
nsIPresShell::SetCapturingContent(GetContent(), CAPTURE_IGNOREALLOWED);
|
2007-04-20 14:56:49 +04:00
|
|
|
|
|
|
|
// remember current mouse coordinates.
|
2015-02-04 23:21:03 +03:00
|
|
|
mLastPoint = aEvent->refPoint;
|
2007-04-20 14:56:49 +04:00
|
|
|
}
|
|
|
|
}
|
2005-11-29 02:56:44 +03:00
|
|
|
|
2006-11-17 00:35:39 +03:00
|
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
2011-10-17 18:59:28 +04:00
|
|
|
doDefault = false;
|
2006-11-17 00:35:39 +03:00
|
|
|
}
|
2005-11-29 02:56:44 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
2006-11-17 00:35:39 +03:00
|
|
|
case NS_MOUSE_BUTTON_UP: {
|
2013-10-22 12:55:20 +04:00
|
|
|
if (mTrackingMouseMove &&
|
|
|
|
aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) {
|
2005-11-29 02:56:44 +03:00
|
|
|
// we're done tracking.
|
2011-10-17 18:59:28 +04:00
|
|
|
mTrackingMouseMove = false;
|
2005-11-29 02:56:44 +03:00
|
|
|
|
|
|
|
// end capture
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIPresShell::SetCapturingContent(nullptr, 0);
|
2005-11-29 02:56:44 +03:00
|
|
|
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
2011-10-17 18:59:28 +04:00
|
|
|
doDefault = false;
|
2005-11-29 02:56:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_MOUSE_MOVE: {
|
|
|
|
if(mTrackingMouseMove)
|
|
|
|
{
|
2015-02-04 23:21:03 +03:00
|
|
|
LayoutDeviceIntPoint nsMoveBy = aEvent->refPoint - mLastPoint;
|
2007-04-20 14:56:49 +04:00
|
|
|
|
|
|
|
nsIFrame* parent = GetParent();
|
2012-07-31 04:43:28 +04:00
|
|
|
while (parent) {
|
|
|
|
nsMenuPopupFrame* popupFrame = do_QueryFrame(parent);
|
|
|
|
if (popupFrame)
|
|
|
|
break;
|
2007-04-20 14:56:49 +04:00
|
|
|
parent = parent->GetParent();
|
2012-07-31 04:43:28 +04:00
|
|
|
}
|
2007-04-20 14:56:49 +04:00
|
|
|
|
2010-02-01 18:11:08 +03:00
|
|
|
// if the titlebar is in a popup, move the popup frame, otherwise
|
2007-04-20 14:56:49 +04:00
|
|
|
// move the widget associated with the window
|
|
|
|
if (parent) {
|
2010-02-01 18:11:08 +03:00
|
|
|
nsMenuPopupFrame* menuPopupFrame = static_cast<nsMenuPopupFrame*>(parent);
|
2011-12-02 01:35:42 +04:00
|
|
|
nsCOMPtr<nsIWidget> widget = menuPopupFrame->GetWidget();
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntRect bounds;
|
2007-04-20 14:56:49 +04:00
|
|
|
widget->GetScreenBounds(bounds);
|
2014-04-08 16:45:52 +04:00
|
|
|
|
|
|
|
int32_t newx = aPresContext->DevPixelsToIntCSSPixels(bounds.x + nsMoveBy.x);
|
|
|
|
int32_t newy = aPresContext->DevPixelsToIntCSSPixels(bounds.y + nsMoveBy.y);
|
|
|
|
menuPopupFrame->MoveTo(newx, newy, false);
|
2007-04-20 14:56:49 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIPresShell* presShell = aPresContext->PresShell();
|
|
|
|
nsPIDOMWindow *window = presShell->GetDocument()->GetWindow();
|
2008-09-28 23:14:28 +04:00
|
|
|
if (window) {
|
|
|
|
window->MoveBy(nsMoveBy.x, nsMoveBy.y);
|
|
|
|
}
|
2005-05-05 00:22:32 +04:00
|
|
|
}
|
2005-11-29 02:56:44 +03:00
|
|
|
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
doDefault = false;
|
2005-11-29 02:56:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2000-07-12 03:37:00 +04:00
|
|
|
|
2013-10-28 13:03:19 +04:00
|
|
|
case NS_MOUSE_CLICK: {
|
|
|
|
WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
|
|
|
|
if (mouseEvent->IsLeftClickEvent()) {
|
|
|
|
MouseClicked(aPresContext, mouseEvent);
|
2006-11-17 00:35:39 +03:00
|
|
|
}
|
2000-07-12 03:37:00 +04:00
|
|
|
break;
|
2013-10-28 13:03:19 +04:00
|
|
|
}
|
2000-07-12 03:37:00 +04:00
|
|
|
}
|
2005-11-29 02:56:44 +03:00
|
|
|
|
|
|
|
if ( doDefault )
|
|
|
|
return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
2000-07-12 03:37:00 +04:00
|
|
|
else
|
2005-11-29 02:56:44 +03:00
|
|
|
return NS_OK;
|
2000-07-12 03:37:00 +04:00
|
|
|
}
|
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
void
|
2013-10-02 07:46:03 +04:00
|
|
|
nsTitleBarFrame::MouseClicked(nsPresContext* aPresContext,
|
2013-10-28 13:03:19 +04:00
|
|
|
WidgetMouseEvent* aEvent)
|
2000-07-12 03:37:00 +04:00
|
|
|
{
|
|
|
|
// Execute the oncommand event handler.
|
2009-06-30 11:56:40 +04:00
|
|
|
nsContentUtils::DispatchXULCommand(mContent,
|
2012-12-16 05:26:03 +04:00
|
|
|
aEvent && aEvent->mFlags.mIsTrusted);
|
2000-07-12 03:37:00 +04:00
|
|
|
}
|