Changeset 96566 in webkit


Ignore:
Timestamp:
Oct 3, 2011 7:26:10 PM (13 years ago)
Author:
Darin Adler
Message:

Change cursor to hand over missing plug-in message
https://bugs.webkit.org/show_bug.cgi?id=69312

Reviewed by Sam Weinig.

No tests because we currently don't have any test machinery for cursors.

  • page/EventHandler.cpp:

(WebCore::OptionalCursor::OptionalCursor): Added. Construct an object
to represent either a cursor, or no cursor change.
(WebCore::OptionalCursor::isCursorChange): Added.
(WebCore::OptionalCursor::cursor): Added.
(WebCore::EventHandler::selectCursor): Changed return type to OptionalCursor,
moved some special cases from handleMouseMoveEvent in here. Moved the logic
for plug-ins and framesets into the specific renderer classes for those.
Added a call to the new getCursor virtual function.
(WebCore::EventHandler::handleMouseMoveEvent): Changed cursor setting code to
just be a call to selectCursor and then setCursor. Plug-in-specific code is now
in RenderWidget.

  • page/EventHandler.h: Changed return type of selectCursor.
  • page/MouseEventWithHitTestResults.cpp: Made some functions be inline.
  • page/MouseEventWithHitTestResults.h:

(WebCore::MouseEventWithHitTestResults::localPoint): Made this inline.
(WebCore::MouseEventWithHitTestResults::scrollbar): Made this inline.
Yes, this has nothing to do with the rest of the patch, but it's good.

  • rendering/RenderEmbeddedObject.cpp:

(WebCore::RenderEmbeddedObject::getReplacementTextGeometry): Made const.
(WebCore::RenderEmbeddedObject::isInMissingPluginIndicator): Made const.
Overloaded so it can be called with a point rather than an event.
(WebCore::shouldMissingPluginMessageBeButton): Added. Helps streamline
the logic below.
(WebCore::RenderEmbeddedObject::handleMissingPluginIndicatorEvent):
Changed to use shouldMissingPluginMessageBeButton.
(WebCore::RenderEmbeddedObject::getCursor): Added. Sets the cursor to
a hand when over the missing plug-in message.

  • rendering/RenderEmbeddedObject.h: Added getCursor override. Also updated

for other changes above.

  • rendering/RenderFrameSet.cpp:

(WebCore::RenderFrameSet::getCursor): Added. Contains the logic that used
to be hardcoded in EventHandler::selectCursor about cursors when over
resizable frame borders.

  • rendering/RenderFrameSet.h: Added getCursor.
  • rendering/RenderObject.cpp:

(WebCore::RenderObject::getCursor): Added. Returns SetCursorBasedOnStyle.

  • rendering/RenderObject.h: Added getCursor.
  • rendering/RenderWidget.cpp:

(WebCore::RenderWidget::getCursor): Added. Contains the logic that used
to be hardcoded in EventHandler::handleMouseMoveEvent to prevent setting
the cursor when the pointer is over a plug-in. This new code is much better,
because it only kicks in when there is actually a plug-in present. The old
was based on the HTML tag!

  • rendering/RenderWidget.h: Added getCursor.
Location:
trunk/Source/WebCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r96561 r96566  
     12011-10-03  Darin Adler  <darin@apple.com>
     2
     3        Change cursor to hand over missing plug-in message
     4        https://bugs.webkit.org/show_bug.cgi?id=69312
     5
     6        Reviewed by Sam Weinig.
     7
     8        No tests because we currently don't have any test machinery for cursors.
     9
     10        * page/EventHandler.cpp:
     11        (WebCore::OptionalCursor::OptionalCursor): Added. Construct an object
     12        to represent either a cursor, or no cursor change.
     13        (WebCore::OptionalCursor::isCursorChange): Added.
     14        (WebCore::OptionalCursor::cursor): Added.
     15        (WebCore::EventHandler::selectCursor): Changed return type to OptionalCursor,
     16        moved some special cases from handleMouseMoveEvent in here. Moved the logic
     17        for plug-ins and framesets into the specific renderer classes for those.
     18        Added a call to the new getCursor virtual function.
     19        (WebCore::EventHandler::handleMouseMoveEvent): Changed cursor setting code to
     20        just be a call to selectCursor and then setCursor. Plug-in-specific code is now
     21        in RenderWidget.
     22
     23        * page/EventHandler.h: Changed return type of selectCursor.
     24
     25        * page/MouseEventWithHitTestResults.cpp: Made some functions be inline.
     26        * page/MouseEventWithHitTestResults.h:
     27        (WebCore::MouseEventWithHitTestResults::localPoint): Made this inline.
     28        (WebCore::MouseEventWithHitTestResults::scrollbar): Made this inline.
     29        Yes, this has nothing to do with the rest of the patch, but it's good.
     30
     31        * rendering/RenderEmbeddedObject.cpp:
     32        (WebCore::RenderEmbeddedObject::getReplacementTextGeometry): Made const.
     33        (WebCore::RenderEmbeddedObject::isInMissingPluginIndicator): Made const.
     34        Overloaded so it can be called with a point rather than an event.
     35        (WebCore::shouldMissingPluginMessageBeButton): Added. Helps streamline
     36        the logic below.
     37        (WebCore::RenderEmbeddedObject::handleMissingPluginIndicatorEvent):
     38        Changed to use shouldMissingPluginMessageBeButton.
     39        (WebCore::RenderEmbeddedObject::getCursor): Added. Sets the cursor to
     40        a hand when over the missing plug-in message.
     41        * rendering/RenderEmbeddedObject.h: Added getCursor override. Also updated
     42        for other changes above.
     43
     44        * rendering/RenderFrameSet.cpp:
     45        (WebCore::RenderFrameSet::getCursor): Added. Contains the logic that used
     46        to be hardcoded in EventHandler::selectCursor about cursors when over
     47        resizable frame borders.
     48        * rendering/RenderFrameSet.h: Added getCursor.
     49
     50        * rendering/RenderObject.cpp:
     51        (WebCore::RenderObject::getCursor): Added. Returns SetCursorBasedOnStyle.
     52        * rendering/RenderObject.h: Added getCursor.
     53
     54        * rendering/RenderWidget.cpp:
     55        (WebCore::RenderWidget::getCursor): Added. Contains the logic that used
     56        to be hardcoded in EventHandler::handleMouseMoveEvent to prevent setting
     57        the cursor when the pointer is over a plug-in. This new code is much better,
     58        because it only kicks in when there is actually a plug-in present. The old
     59        was based on the HTML tag!
     60        * rendering/RenderWidget.h: Added getCursor.
     61
    1622011-10-03  Anders Carlsson  <andersca@apple.com>
    263
  • trunk/Source/WebCore/page/EventHandler.cpp

    r95964 r96566  
    128128const double fakeMouseMoveInterval = 0.1;
    129129
     130enum NoCursorChangeType { NoCursorChange };
     131
     132class OptionalCursor {
     133public:
     134    OptionalCursor(NoCursorChangeType) : m_isCursorChange(false) { }
     135    OptionalCursor(const Cursor& cursor) : m_isCursorChange(true), m_cursor(cursor) { }
     136
     137    bool isCursorChange() const { return m_isCursorChange; }
     138    const Cursor& cursor() const { return m_cursor; }
     139
     140private:
     141    bool m_isCursorChange;
     142    Cursor m_cursor;
     143};
     144
    130145static inline bool scrollNode(float delta, WheelEvent::Granularity granularity, ScrollDirection positiveDirection, ScrollDirection negativeDirection, Node* node, Node** stopNode)
    131146{
     
    11511166}
    11521167
    1153 Cursor EventHandler::selectCursor(const MouseEventWithHitTestResults& event, Scrollbar* scrollbar)
    1154 {
     1168OptionalCursor EventHandler::selectCursor(const MouseEventWithHitTestResults& event, Scrollbar* scrollbar)
     1169{
     1170    if (m_resizeLayer && m_resizeLayer->inResizeMode())
     1171        return NoCursorChange;
     1172
     1173    Page* page = m_frame->page();
     1174    if (!page)
     1175        return NoCursorChange;
     1176    if (page->mainFrame()->eventHandler()->m_panScrollInProgress)
     1177        return NoCursorChange;
     1178
    11551179    Node* node = targetNode(event);
    11561180    RenderObject* renderer = node ? node->renderer() : 0;
    11571181    RenderStyle* style = renderer ? renderer->style() : 0;
    1158 
    11591182    bool horizontalText = !style || style->isHorizontalWritingMode();
    11601183    const Cursor& iBeam = horizontalText ? iBeamCursor() : verticalTextCursor();
     
    11651188        return iBeam;
    11661189
    1167     if (renderer && renderer->isFrameSet()) {
    1168         RenderFrameSet* frameSetRenderer = toRenderFrameSet(renderer);
    1169         if (frameSetRenderer->canResizeRow(event.localPoint()))
    1170             return rowResizeCursor();
    1171         if (frameSetRenderer->canResizeColumn(event.localPoint()))
    1172             return columnResizeCursor();
     1190    if (renderer) {
     1191        Cursor overrideCursor;
     1192        switch (renderer->getCursor(event.localPoint(), overrideCursor)) {
     1193        case SetCursorBasedOnStyle:
     1194            break;
     1195        case SetCursor:
     1196            return overrideCursor;
     1197        case DoNotSetCursor:
     1198            return NoCursorChange;
     1199        }
    11731200    }
    11741201
     
    16301657        if (scrollbar && !m_mousePressed)
    16311658            scrollbar->mouseMoved(mouseEvent); // Handle hover effects on platforms that support visual feedback on scrollbar hovering.
    1632         if (Page* page = m_frame->page()) {
    1633             if ((!m_resizeLayer || !m_resizeLayer->inResizeMode()) && !page->mainFrame()->eventHandler()->m_panScrollInProgress) {
    1634                 // Plugins set cursor on their own. The only case WebKit intervenes is resetting cursor to arrow on mouse enter,
    1635                 // in case the particular plugin doesn't manipulate cursor at all. Thus,  even a CSS cursor set on body has no
    1636                 // effect on plugins (which matches Firefox).
    1637                 bool overPluginElement = false;
    1638                 if (targetNode(mev) && targetNode(mev)->isHTMLElement()) {
    1639                     HTMLElement* el = toHTMLElement(targetNode(mev));
    1640                     overPluginElement = el->hasTagName(appletTag) || el->hasTagName(objectTag) || el->hasTagName(embedTag);
    1641                 }
    1642                 if (!overPluginElement) {
    1643                     if (FrameView* view = m_frame->view())
    1644                         view->setCursor(selectCursor(mev, scrollbar));
    1645                 }
    1646             }
     1659        if (FrameView* view = m_frame->view()) {
     1660            OptionalCursor optionalCursor = selectCursor(mev, scrollbar);
     1661            if (optionalCursor.isCursorChange())
     1662                view->setCursor(optionalCursor.cursor());
    16471663        }
    16481664    }
  • trunk/Source/WebCore/page/EventHandler.h

    r93053 r96566  
    5151
    5252class Clipboard;
    53 class Cursor;
    5453class Event;
    5554class EventTarget;
     
    6362class MouseEventWithHitTestResults;
    6463class Node;
     64class OptionalCursor;
    6565class PlatformKeyboardEvent;
    6666class PlatformTouchEvent;
     
    239239    bool handleMouseReleaseEvent(const MouseEventWithHitTestResults&);
    240240
    241     Cursor selectCursor(const MouseEventWithHitTestResults&, Scrollbar*);
     241    OptionalCursor selectCursor(const MouseEventWithHitTestResults&, Scrollbar*);
    242242#if ENABLE(PAN_SCROLLING)
    243243    void updatePanScrollState();
  • trunk/Source/WebCore/page/MouseEventWithHitTestResults.cpp

    r90603 r96566  
    3434}
    3535
    36 const LayoutPoint MouseEventWithHitTestResults::localPoint() const
    37 {
    38     return m_hitTestResult.localPoint();
    39 }
    40 
    41 Scrollbar* MouseEventWithHitTestResults::scrollbar() const
    42 {
    43     return m_hitTestResult.scrollbar();
    44 }
    45 
    4636bool MouseEventWithHitTestResults::isOverLink() const
    4737{
  • trunk/Source/WebCore/page/MouseEventWithHitTestResults.h

    r90603 r96566  
    3535    const PlatformMouseEvent& event() const { return m_event; }
    3636    const HitTestResult& hitTestResult() const { return m_hitTestResult; }
    37     const LayoutPoint localPoint() const;
    38     Scrollbar* scrollbar() const;
     37    LayoutPoint localPoint() const { return m_hitTestResult.localPoint(); }
     38    Scrollbar* scrollbar() const { return m_hitTestResult.scrollbar(); }
    3939    bool isOverLink() const;
    4040    bool isOverWidget() const { return m_hitTestResult.isOverWidget(); }
  • trunk/Source/WebCore/rendering/RenderEmbeddedObject.cpp

    r94912 r96566  
    2727#include "Chrome.h"
    2828#include "ChromeClient.h"
     29#include "Cursor.h"
    2930#include "CSSValueKeywords.h"
    3031#include "Font.h"
     
    181182}
    182183
    183 bool RenderEmbeddedObject::getReplacementTextGeometry(const LayoutPoint& accumulatedOffset, FloatRect& contentRect, Path& path, FloatRect& replacementTextRect, Font& font, TextRun& run, float& textWidth)
     184bool RenderEmbeddedObject::getReplacementTextGeometry(const LayoutPoint& accumulatedOffset, FloatRect& contentRect, Path& path, FloatRect& replacementTextRect, Font& font, TextRun& run, float& textWidth) const
    184185{
    185186    contentRect = contentBoxRect();
     
    250251}
    251252 
    252 bool RenderEmbeddedObject::isInMissingPluginIndicator(MouseEvent* event)
     253bool RenderEmbeddedObject::isInMissingPluginIndicator(const LayoutPoint& point) const
    253254{
    254255    FloatRect contentRect;
     
    258259    TextRun run("");
    259260    float textWidth;
    260     if (!getReplacementTextGeometry(IntPoint(), contentRect, path, replacementTextRect, font, run, textWidth))
    261         return false;
    262    
    263     return path.contains(absoluteToLocal(event->absoluteLocation(), false, true));
     261    return getReplacementTextGeometry(IntPoint(), contentRect, path, replacementTextRect, font, run, textWidth)
     262        && path.contains(point);
     263}
     264
     265bool RenderEmbeddedObject::isInMissingPluginIndicator(MouseEvent* event) const
     266{
     267    return isInMissingPluginIndicator(roundedLayoutPoint(absoluteToLocal(event->absoluteLocation(), false, true)));
     268}
     269
     270static bool shouldMissingPluginMessageBeButton(Document* document)
     271{
     272    Page* page = document->page();
     273    return page && page->chrome()->client()->shouldMissingPluginMessageBeButton();
    264274}
    265275
    266276void RenderEmbeddedObject::handleMissingPluginIndicatorEvent(Event* event)
    267277{
    268     if (Page* page = document()->page()) {
    269         if (!page->chrome()->client()->shouldMissingPluginMessageBeButton())
    270             return;
    271     }
     278    if (!shouldMissingPluginMessageBeButton(document()))
     279        return;
    272280   
    273281    if (!event->isMouseEvent())
     
    308316}
    309317
    310 }
     318CursorDirective RenderEmbeddedObject::getCursor(const LayoutPoint& point, Cursor& cursor) const
     319{
     320    if (m_showsMissingPluginIndicator && shouldMissingPluginMessageBeButton(document()) && isInMissingPluginIndicator(point)) {
     321        cursor = handCursor();
     322        return SetCursor;
     323    }
     324    return RenderPart::getCursor(point, cursor);
     325}
     326
     327}
  • trunk/Source/WebCore/rendering/RenderEmbeddedObject.h

    r90667 r96566  
    5959    virtual void paintReplaced(PaintInfo&, const LayoutPoint&);
    6060    virtual void paint(PaintInfo&, const LayoutPoint&);
     61    virtual CursorDirective getCursor(const LayoutPoint&, Cursor&) const;
    6162
    6263#if USE(ACCELERATED_COMPOSITING)
     
    6869   
    6970    void setMissingPluginIndicatorIsPressed(bool);
    70     bool isInMissingPluginIndicator(MouseEvent*);
    71     bool getReplacementTextGeometry(const LayoutPoint& accumulatedOffset, FloatRect& contentRect, Path&, FloatRect& replacementTextRect, Font&, TextRun&, float& textWidth);
     71    bool isInMissingPluginIndicator(MouseEvent*) const;
     72    bool isInMissingPluginIndicator(const LayoutPoint&) const;
     73    bool getReplacementTextGeometry(const LayoutPoint& accumulatedOffset, FloatRect& contentRect, Path&, FloatRect& replacementTextRect, Font&, TextRun&, float& textWidth) const;
    7274
    7375    String m_replacementText;
  • trunk/Source/WebCore/rendering/RenderFrameSet.cpp

    r96385 r96566  
    2525#include "RenderFrameSet.h"
    2626
     27#include "Cursor.h"
    2728#include "Document.h"
    2829#include "EventHandler.h"
     
    800801}
    801802
     803CursorDirective RenderFrameSet::getCursor(const LayoutPoint& point, Cursor& cursor) const
     804{
     805    if (canResizeRow(point)) {
     806        cursor = rowResizeCursor();
     807        return SetCursor;
     808    }
     809    if (canResizeColumn(point)) {
     810        cursor = columnResizeCursor();
     811        return SetCursor;
     812    }
     813    return RenderBox::getCursor(point, cursor);
     814}
     815
    802816} // namespace WebCore
  • trunk/Source/WebCore/rendering/RenderFrameSet.h

    r90515 r96566  
    6969    bool isResizingColumn() const;
    7070
    71     bool canResizeRow(const IntPoint&) const;
    72     bool canResizeColumn(const IntPoint&) const;
     71    bool canResizeRow(const LayoutPoint&) const;
     72    bool canResizeColumn(const LayoutPoint&) const;
    7373
    7474    void notifyFrameEdgeInfoChanged();
     
    100100    virtual void paint(PaintInfo&, const LayoutPoint&);
    101101    virtual bool isChildAllowed(RenderObject*, RenderStyle*) const;
     102    virtual CursorDirective getCursor(const LayoutPoint&, Cursor&) const;
    102103
    103104    inline HTMLFrameSetElement* frameSet() const;
  • trunk/Source/WebCore/rendering/RenderObject.cpp

    r96408 r96566  
    26912691}
    26922692
     2693CursorDirective RenderObject::getCursor(const LayoutPoint&, Cursor&) const
     2694{
     2695    return SetCursorBasedOnStyle;
     2696}
     2697
    26932698#if ENABLE(SVG)
     2699
    26942700RenderSVGResourceContainer* RenderObject::toRenderSVGResourceContainer()
    26952701{
  • trunk/Source/WebCore/rendering/RenderObject.h

    r96408 r96566  
    4747class AffineTransform;
    4848class AnimationController;
     49class Cursor;
    4950class HitTestResult;
    5051class InlineBox;
     
    6667
    6768struct PaintInfo;
     69
     70enum CursorDirective {
     71    SetCursorBasedOnStyle,
     72    SetCursor,
     73    DoNotSetCursor
     74};
    6875
    6976enum HitTestFilter {
     
    659666    virtual RenderStyle* outlineStyleForRepaint() const { return style(); }
    660667   
    661     void getTextDecorationColors(int decorations, Color& underline, Color& overline,
    662                                  Color& linethrough, bool quirksMode = false);
     668    virtual CursorDirective getCursor(const LayoutPoint&, Cursor&) const;
     669
     670    void getTextDecorationColors(int decorations, Color& underline, Color& overline, Color& linethrough, bool quirksMode = false);
    663671
    664672    // Return the RenderBox in the container chain which is responsible for painting this object, or 0
  • trunk/Source/WebCore/rendering/RenderWidget.cpp

    r95749 r96566  
    386386}
    387387
     388CursorDirective RenderWidget::getCursor(const LayoutPoint& point, Cursor& cursor) const
     389{
     390    if (widget() && widget()->isPluginViewBase()) {
     391        // A plug-in is responsible for setting the cursor when the pointer is over it.
     392        return DoNotSetCursor;
     393    }
     394    return RenderReplaced::getCursor(point, cursor);
     395}
     396
    388397} // namespace WebCore
  • trunk/Source/WebCore/rendering/RenderWidget.h

    r95725 r96566  
    6060    virtual void layout();
    6161    virtual void paint(PaintInfo&, const LayoutPoint&);
     62    virtual CursorDirective getCursor(const LayoutPoint&, Cursor&) const;
    6263
    6364private:
Note: See TracChangeset for help on using the changeset viewer.