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 "FrameView.h"
     33 #include "Frame.h"
     34 #include "GraphicsContext.h"
     35 #include "IntRect.h"
     36 #include "PlatformMouseEvent.h"
     37 #include "ScrollbarTheme.h"
     38 
     39 #include <QApplication>
     40 #include <QDebug>
     41 #include <QPainter>
     42 #include <QStyle>
     43 #include <QMenu>
     44 
     45 using namespace std;
     46 
     47 namespace WebCore {
     48 
     49 bool Scrollbar::contextMenu(const PlatformMouseEvent& event)
     50 {
     51 #ifndef QT_NO_CONTEXTMENU
     52     if (!QApplication::style()->styleHint(QStyle::SH_ScrollBar_ContextMenu))
     53         return true;
     54 
     55     bool horizontal = (m_orientation == HorizontalScrollbar);
     56 
     57     QMenu menu;
     58     QAction* actScrollHere = menu.addAction(QCoreApplication::translate("QWebPage", "Scroll here"));
     59     menu.addSeparator();
     60 
     61     QAction* actScrollTop = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Left edge") : QCoreApplication::translate("QWebPage", "Top"));
     62     QAction* actScrollBottom = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Right edge") : QCoreApplication::translate("QWebPage", "Bottom"));
     63     menu.addSeparator();
     64 
     65     QAction* actPageUp = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Page left") : QCoreApplication::translate("QWebPage", "Page up"));
     66     QAction* actPageDown = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Page right") : QCoreApplication::translate("QWebPage", "Page down"));
     67     menu.addSeparator();
     68 
     69     QAction* actScrollUp = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Scroll left") : QCoreApplication::translate("QWebPage", "Scroll up"));
     70     QAction* actScrollDown = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Scroll right") : QCoreApplication::translate("QWebPage", "Scroll down"));
     71 
     72     const QPoint globalPos = QPoint(event.globalX(), event.globalY());
     73     QAction* actionSelected = menu.exec(globalPos);
     74 
     75     if (!actionSelected)
     76         { /* Do nothing */ }
     77     else if (actionSelected == actScrollHere) {
     78         const QPoint pos = convertFromContainingWindow(event.pos());
     79         moveThumb(horizontal ? pos.x() : pos.y());
     80     } else if (actionSelected == actScrollTop)
     81         setValue(0);
     82     else if (actionSelected == actScrollBottom)
     83         setValue(maximum());
     84     else if (actionSelected == actPageUp)
     85         scroll(horizontal ? ScrollLeft: ScrollUp, ScrollByPage, 1);
     86     else if (actionSelected == actPageDown)
     87         scroll(horizontal ? ScrollRight : ScrollDown, ScrollByPage, 1);
     88     else if (actionSelected == actScrollUp)
     89         scroll(horizontal ? ScrollLeft : ScrollUp, ScrollByLine, 1);
     90     else if (actionSelected == actScrollDown)
     91         scroll(horizontal ? ScrollRight : ScrollDown, ScrollByLine, 1);
     92 #endif // QT_NO_CONTEXTMENU
     93     return true;
     94 }
     95 
     96 }
     97 
     98 // vim: ts=4 sw=4 et
     99