Changeset 29887 in webkit


Ignore:
Timestamp:
Jan 31, 2008, 10:47:44 AM (17 years ago)
Author:
Adam Roben
Message:

Let WebCore take care of the highlight drawing entirely

WebCore:

Put more knowledge about the node highlight in WebCore

InspectorController now calculates the overlay rect and node rect when
drawing the node highlight instead of having them be passed in.
InspectorController now holds onto the highlighted node so that it can
determine these rects.

Once all platforms are calling down to drawNodeHighlight instead of
drawing the highlight themselves, we can change
InspectorClient::highlight(Node*) to something like
InspectorClient::updateAndShowHighlight().

This also fixes Bug 14264: Node highlight makes it impossible to
scroll the page
<http://bugs.webkit.org/show_bug.cgi?id=14264>
<rdar://5712788>

Reviewed by Darin.

  • page/InspectorController.cpp: (WebCore::InspectorController::highlight): Store the node for use in drawNodeHighlight. (WebCore::InspectorController::drawNodeHighlight): Changed to be a const instance method. Now calculates the overlay rect and node rect instead of having them passed in.
  • page/InspectorController.h:

WebKit/win:

Let WebCore take care of the highlight drawing entirely

Reviewed by Darin.

  • WebInspectorClient.cpp: (WebInspectorClient::highlight): We now just show our highlight window and let WebCore figure out what/where to paint. Once all ports follow suit the Node* parameter to this method should be removed entirely, and the name should probably change to updateAndShowHighlight or something similar.
  • WebNodeHighlight.cpp: Renamed m_webView to m_inspectedWebViewWindow. (WebNodeHighlight::WebNodeHighlight): Now takes a WebView* parameter. (WebNodeHighlight::show): Renamed from highlight(). Now gets the WebView's HWND. Updated for member rename/removal. (WebNodeHighlight::updateWindow): Updated for member rename and for InspectorController changes.
  • WebNodeHighlight.h: Added m_inspectedWebView member, removed m_rect member, renamed highlight(Node*) -> show().
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r29886 r29887  
     12008-01-31  Adam Roben  <aroben@apple.com>
     2
     3        Put more knowledge about the node highlight in WebCore
     4
     5        InspectorController now calculates the overlay rect and node rect when
     6        drawing the node highlight instead of having them be passed in.
     7        InspectorController now holds onto the highlighted node so that it can
     8        determine these rects.
     9
     10        Once all platforms are calling down to drawNodeHighlight instead of
     11        drawing the highlight themselves, we can change
     12        InspectorClient::highlight(Node*) to something like
     13        InspectorClient::updateAndShowHighlight().
     14
     15        This also fixes Bug 14264: Node highlight makes it impossible to
     16        scroll the page
     17        <http://bugs.webkit.org/show_bug.cgi?id=14264>
     18        <rdar://5712788>
     19
     20        Reviewed by Darin.
     21
     22        * page/InspectorController.cpp:
     23        (WebCore::InspectorController::highlight): Store the node for use in
     24        drawNodeHighlight.
     25        (WebCore::InspectorController::drawNodeHighlight): Changed to be a
     26        const instance method. Now calculates the overlay rect and node rect
     27        instead of having them passed in.
     28        * page/InspectorController.h:
     29
    1302008-01-31  Adam Roben  <aroben@apple.com>
    231
  • trunk/WebCore/page/InspectorController.cpp

    r29886 r29887  
    4141#include "FrameLoader.h"
    4242#include "FrameTree.h"
     43#include "FrameView.h"
    4344#include "GraphicsContext.h"
    4445#include "HTMLFrameOwnerElement.h"
     
    669670        return;
    670671    ASSERT_ARG(node, node);
     672    m_highlightedNode = node;
    671673    m_client->highlight(node);
    672674}
     
    15791581}
    15801582
    1581 void InspectorController::drawNodeHighlight(GraphicsContext& context, const IntRect& overlayRect, const IntRect& highlightedNodeRect)
     1583void InspectorController::drawNodeHighlight(GraphicsContext& context) const
    15821584{
    15831585    static const Color overlayFillColor(0, 0, 0, 128);
    15841586    static const int outlineThickness = 1;
    15851587
    1586     context.clipOut(highlightedNodeRect);
     1588    if (!m_highlightedNode)
     1589        return;
     1590
     1591    FrameView* view = m_inspectedPage->mainFrame()->view();
     1592    FloatRect overlayRect = static_cast<ScrollView*>(view)->visibleContentRect();
     1593    context.translate(-overlayRect.x(), -overlayRect.y());
     1594
     1595    RenderObject* renderer = m_highlightedNode->renderer();
     1596    if (!renderer)
     1597        return;
     1598    IntRect nodeRect(renderer->absoluteBoundingBoxRect());
     1599
     1600    if (!overlayRect.contains(nodeRect) && !nodeRect.contains(enclosingIntRect(overlayRect))) {
     1601        Element* element;
     1602        if (m_highlightedNode->isElementNode())
     1603            element = static_cast<Element*>(m_highlightedNode.get());
     1604        else
     1605            element = static_cast<Element*>(m_highlightedNode->parent());
     1606        element->scrollIntoViewIfNeeded();
     1607    }
     1608
     1609    context.clipOut(nodeRect);
    15871610
    15881611    context.fillRect(overlayRect, overlayFillColor);
    15891612
    1590     IntRect outlineRect(highlightedNodeRect);
     1613    IntRect outlineRect(nodeRect);
    15911614    outlineRect.inflate(outlineThickness);
    15921615    context.fillRect(outlineRect, Color::white);
  • trunk/WebCore/page/InspectorController.h

    r29886 r29887  
    121121    void moveWindowBy(float x, float y) const;
    122122
    123     static void drawNodeHighlight(GraphicsContext&, const IntRect& overlayRect, const IntRect& highlightedNodeRect);
     123    void drawNodeHighlight(GraphicsContext&) const;
    124124
    125125private:
     
    170170    SpecialPanels m_showAfterVisible;
    171171    long long m_nextIdentifier;
     172    RefPtr<Node> m_highlightedNode;
    172173};
    173174
  • trunk/WebKit/win/ChangeLog

    r29886 r29887  
     12008-01-31  Adam Roben  <aroben@apple.com>
     2
     3        Let WebCore take care of the highlight drawing entirely
     4
     5        Reviewed by Darin.
     6
     7        * WebInspectorClient.cpp:
     8        (WebInspectorClient::highlight): We now just show our highlight
     9        window and let WebCore figure out what/where to paint. Once all ports
     10        follow suit the Node* parameter to this method should be removed
     11        entirely, and the name should probably change to
     12        updateAndShowHighlight or something similar.
     13        * WebNodeHighlight.cpp: Renamed m_webView to m_inspectedWebViewWindow.
     14        (WebNodeHighlight::WebNodeHighlight): Now takes a WebView* parameter.
     15        (WebNodeHighlight::show): Renamed from highlight(). Now gets the
     16        WebView's HWND. Updated for member rename/removal.
     17        (WebNodeHighlight::updateWindow): Updated for member rename and for
     18        InspectorController changes.
     19        * WebNodeHighlight.h: Added m_inspectedWebView member, removed m_rect
     20        member, renamed highlight(Node*) -> show().
     21
    1222008-01-31  Adam Roben  <aroben@apple.com>
    223
  • trunk/WebKit/win/WebInspectorClient.cpp

    r29863 r29887  
    271271}
    272272
    273 void WebInspectorClient::highlight(Node* node)
    274 {
    275     ASSERT_ARG(node, node);
    276 
    277     HWND hwnd;
    278     if (FAILED(m_inspectedWebView->viewWindow((OLE_HANDLE*)&hwnd)))
    279         return;
    280     RECT rect;
    281     ::GetClientRect(hwnd, &rect);
    282     IntRect webViewRect(rect);
    283 
    284     RenderObject* renderer = node->renderer();
    285     if (!renderer)
    286         return;
    287     IntRect nodeRect(renderer->absoluteBoundingBoxRect());
    288 
    289     if (!webViewRect.contains(nodeRect) && !nodeRect.contains(webViewRect)) {
    290         Element* element;
    291         if (node->isElementNode())
    292             element = static_cast<Element*>(node);
    293         else
    294             element = static_cast<Element*>(node->parent());
    295         element->scrollIntoViewIfNeeded();
    296     }
    297 
    298     IntSize offset = m_inspectedWebView->page()->mainFrame()->view()->scrollOffset();
    299     nodeRect.move(-offset);
    300 
     273void WebInspectorClient::highlight(Node*)
     274{
    301275    if (!m_highlight)
    302         m_highlight.set(new WebNodeHighlight(hwnd));
    303 
    304     m_highlight->highlight(nodeRect);
     276        m_highlight.set(new WebNodeHighlight(m_inspectedWebView));
     277
     278    m_highlight->show();
    305279}
    306280
  • trunk/WebKit/win/WebNodeHighlight.cpp

    r29886 r29887  
    3030#include "WebNodeHighlight.h"
    3131
     32#include "WebView.h"
    3233#pragma warning(push, 0)
    3334#include <WebCore/Color.h>
    3435#include <WebCore/GraphicsContext.h>
    3536#include <WebCore/InspectorController.h>
     37#include <WebCore/Page.h>
    3638#include <WebCore/WindowMessageBroadcaster.h>
    3739#pragma warning(pop)
     
    4547static LPCTSTR kWebNodeHighlightPointerProp = TEXT("WebNodeHighlightPointer");
    4648
    47 WebNodeHighlight::WebNodeHighlight(HWND webView)
    48     : m_webView(webView)
     49WebNodeHighlight::WebNodeHighlight(WebView* webView)
     50    : m_inspectedWebView(webView)
     51    , m_inspectedWebViewWindow(0)
    4952    , m_overlay(0)
    5053    , m_observedWindow(0)
     
    6164}
    6265
    63 void WebNodeHighlight::highlight(const IntRect& rect)
     66void WebNodeHighlight::show()
    6467{
    6568    if (!m_overlay) {
     69        if (FAILED(m_inspectedWebView->viewWindow(reinterpret_cast<OLE_HANDLE*>(&m_inspectedWebViewWindow))) || !IsWindow(m_inspectedWebViewWindow))
     70            return;
     71
    6672        registerOverlayClass();
    6773
    6874        m_overlay = ::CreateWindowEx(WS_EX_LAYERED | WS_EX_TOOLWINDOW, kOverlayWindowClassName, 0, WS_POPUP | WS_VISIBLE,
    6975                                     0, 0, 0, 0,
    70                                      m_webView, 0, 0, 0);
     76                                     m_inspectedWebViewWindow, 0, 0, 0);
    7177        if (!m_overlay)
    7278            return;
    7379
    7480        ::SetProp(m_overlay, kWebNodeHighlightPointerProp, reinterpret_cast<HANDLE>(this));
    75         ::SetWindowPos(m_overlay, m_webView, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
    76 
    77         m_observedWindow = GetAncestor(m_webView, GA_ROOT);
     81        ::SetWindowPos(m_overlay, m_inspectedWebViewWindow, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
     82
     83        m_observedWindow = GetAncestor(m_inspectedWebViewWindow, GA_ROOT);
    7884        WindowMessageBroadcaster::addListener(m_observedWindow, this);
    7985    }
    8086
    81     m_rect = rect;
    8287    updateWindow();
    8388    ::ShowWindow(m_overlay, SW_SHOW);
     
    104109
    105110    RECT webViewRect;
    106     ::GetWindowRect(m_webView, &webViewRect);
     111    ::GetWindowRect(m_inspectedWebViewWindow, &webViewRect);
    107112
    108113    SIZE size;
     
    130135    GraphicsContext context(hdc);
    131136
    132     IntRect overlayRect(webViewRect);
    133     overlayRect.setLocation(IntPoint(0, 0));
    134 
    135     InspectorController::drawNodeHighlight(context, overlayRect, m_rect);
     137    m_inspectedWebView->page()->inspectorController()->drawNodeHighlight(context);
    136138
    137139    BLENDFUNCTION bf;
  • trunk/WebKit/win/WebNodeHighlight.h

    r27765 r29887  
    3131
    3232#pragma warning(push, 0)
    33 #include <WebCore/IntRect.h>
    3433#include <WebCore/WindowMessageListener.h>
    3534#pragma warning(pop)
     
    3736#include <windows.h>
    3837
     38class WebView;
     39
    3940class WebNodeHighlight : WebCore::WindowMessageListener {
    4041public:
    41     WebNodeHighlight(HWND webView);
     42    WebNodeHighlight(WebView*);
    4243    ~WebNodeHighlight();
    4344
    44     void highlight(const WebCore::IntRect&);
     45    void show();
    4546    void hide();
    4647
     
    5152    virtual void windowReceivedMessage(HWND, UINT message, WPARAM, LPARAM);
    5253
    53     HWND m_webView;
     54    WebView* m_inspectedWebView;
     55    HWND m_inspectedWebViewWindow;
    5456    HWND m_overlay;
    5557    HWND m_observedWindow;
    56 
    57     WebCore::IntRect m_rect;
    5858
    5959    friend static LRESULT CALLBACK OverlayWndProc(HWND, UINT, WPARAM, LPARAM);
Note: See TracChangeset for help on using the changeset viewer.