Home | History | Annotate | Download | only in qt
      1 /*
      2  * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
      3  * Copyright (C) 2007 Staikos Computing Services Inc. <info (at) staikos.net>
      4  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 #include "config.h"
     29 #include "Scrollbar.h"
     30 
     31 #include "EventHandler.h"
     32 #include "Frame.h"
     33 #include "FrameView.h"
     34 #include "GraphicsContext.h"
     35 #include "IntRect.h"
     36 #include "PlatformMouseEvent.h"
     37 #include "ScrollableArea.h"
     38 #include "ScrollbarTheme.h"
     39 
     40 #include <QApplication>
     41 #include <QDebug>
     42 #include <QMenu>
     43 #include <QPainter>
     44 #include <QStyle>
     45 
     46 using namespace std;
     47 
     48 namespace WebCore {
     49 
     50 bool Scrollbar::contextMenu(const PlatformMouseEvent& event)
     51 {
     52 #ifndef QT_NO_CONTEXTMENU
     53     if (!QApplication::style()->styleHint(QStyle::SH_ScrollBar_ContextMenu))
     54         return true;
     55 
     56     bool horizontal = (m_orientation == HorizontalScrollbar);
     57 
     58     QMenu menu;
     59     QAction* actScrollHere = menu.addAction(QCoreApplication::translate("QWebPage", "Scroll here"));
     60     menu.addSeparator();
     61 
     62     QAction* actScrollTop = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Left edge") : QCoreApplication::translate("QWebPage", "Top"));
     63     QAction* actScrollBottom = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Right edge") : QCoreApplication::translate("QWebPage", "Bottom"));
     64     menu.addSeparator();
     65 
     66     QAction* actPageUp = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Page left") : QCoreApplication::translate("QWebPage", "Page up"));
     67     QAction* actPageDown = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Page right") : QCoreApplication::translate("QWebPage", "Page down"));
     68     menu.addSeparator();
     69 
     70     QAction* actScrollUp = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Scroll left") : QCoreApplication::translate("QWebPage", "Scroll up"));
     71     QAction* actScrollDown = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Scroll right") : QCoreApplication::translate("QWebPage", "Scroll down"));
     72 
     73     const QPoint globalPos = QPoint(event.globalX(), event.globalY());
     74     QAction* actionSelected = menu.exec(globalPos);
     75 
     76     if (actionSelected == actScrollHere) {
     77         // Set the pressed position to the middle of the thumb so that when we
     78         // do move, the delta will be from the current pixel position of the
     79         // thumb to the new position
     80         int position = theme()->trackPosition(this) + theme()->thumbPosition(this) + theme()->thumbLength(this) / 2;
     81         setPressedPos(position);
     82         const QPoint pos = convertFromContainingWindow(event.pos());
     83         moveThumb(horizontal ? pos.x() : pos.y());
     84     } else if (actionSelected == actScrollTop)
     85         scrollableArea()->scroll(horizontal ? ScrollLeft : ScrollUp, ScrollByDocument);
     86     else if (actionSelected == actScrollBottom)
     87         scrollableArea()->scroll(horizontal ? ScrollRight : ScrollDown, ScrollByDocument);
     88     else if (actionSelected == actPageUp)
     89         scrollableArea()->scroll(horizontal ? ScrollLeft : ScrollUp, ScrollByPage);
     90     else if (actionSelected == actPageDown)
     91         scrollableArea()->scroll(horizontal ? ScrollRight : ScrollDown, ScrollByPage);
     92     else if (actionSelected == actScrollUp)
     93         scrollableArea()->scroll(horizontal ? ScrollLeft : ScrollUp, ScrollByLine);
     94     else if (actionSelected == actScrollDown)
     95         scrollableArea()->scroll(horizontal ? ScrollRight : ScrollDown, ScrollByLine);
     96 #endif // QT_NO_CONTEXTMENU
     97     return true;
     98 }
     99 
    100 }
    101 
    102 // vim: ts=4 sw=4 et
    103