mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-12 18:50:08 +00:00
Patch from:
Davor Cubranic Tomi Leppikangas That implements middle mouse click to position on unix. Bug #24117 -r evaughan -a brendan
This commit is contained in:
parent
c4ecf7997b
commit
04d65b243b
@ -59,9 +59,12 @@
|
||||
#include "nsRepeatService.h"
|
||||
#include "nsBoxLayoutState.h"
|
||||
#include "nsSprocketLayout.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#define DEBUG_SLIDER PR_FALSE
|
||||
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
|
||||
nsresult
|
||||
NS_NewSliderFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
||||
@ -98,6 +101,13 @@ nsSliderFrame::Init(nsIPresContext* aPresContext,
|
||||
nsIFrame* aPrevInFlow)
|
||||
{
|
||||
nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
|
||||
|
||||
nsresult rv2;
|
||||
mMiddlePref=PR_FALSE;
|
||||
nsCOMPtr<nsIPref> pref = do_GetService(kPrefCID, &rv2);
|
||||
if(NS_SUCCEEDED(rv2))
|
||||
pref->GetBoolPref("middlemouse.scrollbarPosition", &mMiddlePref);
|
||||
|
||||
CreateViewForFrame(aPresContext,this,aContext,PR_TRUE);
|
||||
nsIView* view;
|
||||
GetView(aPresContext, &view);
|
||||
@ -437,6 +447,10 @@ nsSliderFrame::HandleEvent(nsIPresContext* aPresContext,
|
||||
}
|
||||
break;
|
||||
|
||||
case NS_MOUSE_MIDDLE_BUTTON_UP:
|
||||
if(!mMiddlePref)
|
||||
break;
|
||||
|
||||
case NS_MOUSE_LEFT_BUTTON_UP:
|
||||
// stop capturing
|
||||
//printf("stop capturing\n");
|
||||
@ -453,6 +467,67 @@ nsSliderFrame::HandleEvent(nsIPresContext* aPresContext,
|
||||
//return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
||||
return NS_OK;
|
||||
}
|
||||
else if (mMiddlePref && aEvent->message == NS_MOUSE_MIDDLE_BUTTON_DOWN) {
|
||||
// convert coord from twips to pixels
|
||||
nscoord pos = isHorizontal ? aEvent->point.x : aEvent->point.y;
|
||||
float p2t;
|
||||
aPresContext->GetScaledPixelsToTwips(&p2t);
|
||||
nscoord onePixel = NSIntPixelsToTwips(1, p2t);
|
||||
nscoord pospx = pos/onePixel;
|
||||
|
||||
// adjust so that the middle of the thumb is placed under the click
|
||||
nsIFrame* thumbFrame = mFrames.FirstChild();
|
||||
nsSize thumbSize;
|
||||
thumbFrame->GetSize(thumbSize);
|
||||
nscoord thumbLength = isHorizontal ? thumbSize.width : thumbSize.height;
|
||||
thumbLength /= onePixel;
|
||||
pospx -= (thumbLength/2);
|
||||
|
||||
|
||||
// convert to our internal coordinate system
|
||||
pospx = nscoord(pospx/mRatio);
|
||||
|
||||
// set it
|
||||
SetCurrentPosition(scrollbar, thumbFrame, pospx);
|
||||
|
||||
// hack to start dragging
|
||||
|
||||
nsIFrame* parent = this;
|
||||
while(parent != nsnull)
|
||||
{
|
||||
// if we hit a scrollable view make sure we take into account
|
||||
// how much we are scrolled.
|
||||
nsIScrollableView* scrollingView;
|
||||
nsIView* view;
|
||||
parent->GetView(aPresContext, &view);
|
||||
if (view) {
|
||||
nsresult result = view->QueryInterface(NS_GET_IID(nsIScrollableView), (void**)&scrollingView);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nscoord xoff = 0;
|
||||
nscoord yoff = 0;
|
||||
scrollingView->GetScrollPosition(xoff, yoff);
|
||||
isHorizontal ? pos += xoff : pos += yoff;
|
||||
}
|
||||
}
|
||||
|
||||
nsRect r;
|
||||
parent->GetRect(r);
|
||||
isHorizontal ? pos += r.x : pos += r.y;
|
||||
parent->GetParent(&parent);
|
||||
}
|
||||
|
||||
RemoveListener();
|
||||
DragThumb(mPresContext, PR_TRUE);
|
||||
nsRect thumbRect;
|
||||
thumbFrame->GetRect(thumbRect);
|
||||
|
||||
if (isHorizontal)
|
||||
mThumbStart = thumbRect.x;
|
||||
else
|
||||
mThumbStart = thumbRect.y;
|
||||
|
||||
mDragStartPx =pos/onePixel;
|
||||
}
|
||||
|
||||
// XXX hack until handle release is actually called in nsframe.
|
||||
// if (aEvent->message == NS_MOUSE_EXIT_SYNTH || aEvent->message == NS_MOUSE_RIGHT_BUTTON_UP || aEvent->message == NS_MOUSE_LEFT_BUTTON_UP)
|
||||
@ -687,10 +762,73 @@ nsSliderFrame::MouseDown(nsIDOMEvent* aMouseEvent)
|
||||
|
||||
PRUint16 button = 0;
|
||||
mouseEvent->GetButton(&button);
|
||||
if((mMiddlePref && button != 1 && button != 2) ||
|
||||
(!mMiddlePref && button != 1))
|
||||
return NS_OK;
|
||||
|
||||
// only if left button
|
||||
if (button != 1)
|
||||
return NS_OK;
|
||||
// If middle button, first place the middle of the slider thumb
|
||||
// under the click
|
||||
if (button == 2) {
|
||||
|
||||
nscoord pos;
|
||||
nscoord pospx;
|
||||
|
||||
// mouseEvent has click coordinates in pixels, convert to twips first
|
||||
isHorizontal ? mouseEvent->GetClientX(&pospx) : mouseEvent->GetClientY(&pospx);
|
||||
float p2t;
|
||||
// XXX hack
|
||||
mPresContext->GetScaledPixelsToTwips(&p2t);
|
||||
nscoord onePixel = NSIntPixelsToTwips(1, p2t);
|
||||
pos = pospx * onePixel;
|
||||
|
||||
// then get it into our coordinate system by subtracting our parents offsets.
|
||||
nsIFrame* parent = this;
|
||||
while(parent != nsnull) {
|
||||
// if we hit a scrollable view make sure we take into account
|
||||
// how much we are scrolled.
|
||||
nsIScrollableView* scrollingView;
|
||||
nsIView* view;
|
||||
// XXX hack
|
||||
parent->GetView(mPresContext, &view);
|
||||
if (view) {
|
||||
nsresult result = view->QueryInterface(NS_GET_IID(nsIScrollableView), (void**)&scrollingView);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nscoord xoff = 0;
|
||||
nscoord yoff = 0;
|
||||
scrollingView->GetScrollPosition(xoff, yoff);
|
||||
isHorizontal ? pos += xoff : pos += yoff;
|
||||
}
|
||||
}
|
||||
|
||||
nsRect r;
|
||||
parent->GetRect(r);
|
||||
isHorizontal ? pos -= r.x : pos -= r.y;
|
||||
parent->GetParent(&parent);
|
||||
}
|
||||
|
||||
// now convert back into pixels
|
||||
pospx = pos/onePixel;
|
||||
|
||||
// adjust so that the middle of the thumb is placed under the click
|
||||
nsIFrame* thumbFrame = mFrames.FirstChild();
|
||||
nsRect thumbRect;
|
||||
thumbFrame->GetRect(thumbRect);
|
||||
nsSize thumbSize;
|
||||
thumbFrame->GetSize(thumbSize);
|
||||
nscoord thumbLength = isHorizontal ? thumbSize.width : thumbSize.height;
|
||||
thumbLength /= onePixel;
|
||||
pospx -= (thumbLength/2);
|
||||
|
||||
// finally, convert to scrollbar's internal coordinate system
|
||||
pospx = nscoord(pospx/mRatio);
|
||||
|
||||
nsIBox* scrollbarBox = GetScrollbar();
|
||||
nsCOMPtr<nsIContent> scrollbar;
|
||||
GetContentOf(scrollbarBox, getter_AddRefs(scrollbar));
|
||||
|
||||
// set it
|
||||
SetCurrentPosition(scrollbar, thumbFrame, pospx);
|
||||
}
|
||||
|
||||
RemoveListener();
|
||||
DragThumb(mPresContext, PR_TRUE);
|
||||
|
@ -16,14 +16,14 @@
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* AUTHOR: Eric Vaughan
|
||||
*
|
||||
* Contributor(s):
|
||||
* Tomi Leppikangas
|
||||
* Davor Cubranic
|
||||
*/
|
||||
|
||||
//
|
||||
// nsSliderFrame
|
||||
//
|
||||
|
||||
#ifndef nsSliderFrame_h__
|
||||
#define nsSliderFrame_h__
|
||||
|
||||
@ -224,6 +224,7 @@ private:
|
||||
nscoord mThumbStart;
|
||||
|
||||
PRInt32 mCurPos;
|
||||
PRBool mMiddlePref;
|
||||
|
||||
nsIScrollbarListener* mScrollbarListener;
|
||||
|
||||
|
@ -511,6 +511,8 @@ pref("mousewheel.withaltkey.action",2);
|
||||
pref("mousewheel.withaltkey.numlines",1);
|
||||
pref("mousewheel.withaltkey.sysnumlines",false);
|
||||
|
||||
pref("middlemouse.scrollbarPosition", false);
|
||||
|
||||
pref("profile.confirm_automigration",true);
|
||||
|
||||
// Customizable toolbar stuff
|
||||
|
@ -49,6 +49,7 @@ pref("editor.dont_lock_spell_files", true);
|
||||
// Middle-mouse handling
|
||||
pref("middlemouse.paste", true);
|
||||
pref("middlemouse.openNewWindow", true);
|
||||
pref("middlemouse.scrollbarPosition", true);
|
||||
|
||||
// Instead of "delay_images"
|
||||
pref("browser.autoload_images", true);
|
||||
|
@ -1138,6 +1138,20 @@ function BrowserEditBookmarks()
|
||||
return "";
|
||||
}
|
||||
|
||||
function isScrollbar(node)
|
||||
{
|
||||
while (node)
|
||||
{
|
||||
var nodeName = node.nodeName;
|
||||
if (nodeName == "")
|
||||
return false;
|
||||
if (nodeName == "scrollbar")
|
||||
return true;
|
||||
node = node.parentNode;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function browserHandleMiddleClick(event)
|
||||
{
|
||||
var target = event.target;
|
||||
@ -1154,6 +1168,9 @@ function BrowserEditBookmarks()
|
||||
|
||||
if (pref.GetBoolPref("middlemouse.paste"))
|
||||
{
|
||||
if (isScrollbar(target)) {
|
||||
return;
|
||||
}
|
||||
var tagName = target.tagName;
|
||||
if (tagName) tagName = tagName.toLowerCase();
|
||||
var type = target.type;
|
||||
|
Loading…
x
Reference in New Issue
Block a user