2006-03-15 Eric Seidel <eseidel@apple.com>
authoreseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Mar 2006 08:10:17 +0000 (08:10 +0000)
committereseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Mar 2006 08:10:17 +0000 (08:10 +0000)
        Reviewed by darin.

        Push more of MacFrame down into Frame.
        Add visibleContentRect method to ScrollView.

        * bridge/mac/MacFrame.h:
        * bridge/mac/MacFrame.mm:
        (WebCore::MacFrame::imageFromRect):
        (WebCore::MacFrame::setDisplaysWithFocusAttributes):
        (WebCore::MacFrame::bodyBackgroundColor):
        * bridge/mac/WebCoreFrameBridge.mm:
        * page/Frame.cpp:
        (WebCore::Frame::visibleSelectionRect):
        (WebCore::Frame::setDisplaysWithFocusAttributes):
        * page/Frame.h:
        * platform/ScrollView.h:
        * platform/mac/ScrollViewMac.mm:
        (WebCore::ScrollView::visibleWidth):
        (WebCore::ScrollView::visibleHeight):
        (WebCore::ScrollView::visibleContentRect):
        (WebCore::ScrollView::contentsWidth):
        (WebCore::ScrollView::contentsHeight):
        (WebCore::ScrollView::contentsX):
        (WebCore::ScrollView::contentsY):
        (WebCore::ScrollView::scrollXOffset):
        (WebCore::ScrollView::scrollYOffset):
        (WebCore::ScrollView::inWindow):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@13327 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/bridge/mac/MacFrame.h
WebCore/bridge/mac/MacFrame.mm
WebCore/bridge/mac/WebCoreFrameBridge.mm
WebCore/page/Frame.cpp
WebCore/page/Frame.h
WebCore/platform/ScrollView.h
WebCore/platform/mac/ScrollViewMac.mm

index dce9e76dcacbf8a5e1f79d206cd4dffc31a5d320..fd23d5a05ddba2f99101776006aa4d7ba35be03f 100644 (file)
@@ -1,3 +1,33 @@
+2006-03-15  Eric Seidel  <eseidel@apple.com>
+
+        Reviewed by darin.
+
+        Push more of MacFrame down into Frame.
+        Add visibleContentRect method to ScrollView.
+
+        * bridge/mac/MacFrame.h:
+        * bridge/mac/MacFrame.mm:
+        (WebCore::MacFrame::imageFromRect):
+        (WebCore::MacFrame::setDisplaysWithFocusAttributes):
+        (WebCore::MacFrame::bodyBackgroundColor):
+        * bridge/mac/WebCoreFrameBridge.mm:
+        * page/Frame.cpp:
+        (WebCore::Frame::visibleSelectionRect):
+        (WebCore::Frame::setDisplaysWithFocusAttributes):
+        * page/Frame.h:
+        * platform/ScrollView.h:
+        * platform/mac/ScrollViewMac.mm:
+        (WebCore::ScrollView::visibleWidth):
+        (WebCore::ScrollView::visibleHeight):
+        (WebCore::ScrollView::visibleContentRect):
+        (WebCore::ScrollView::contentsWidth):
+        (WebCore::ScrollView::contentsHeight):
+        (WebCore::ScrollView::contentsX):
+        (WebCore::ScrollView::contentsY):
+        (WebCore::ScrollView::scrollXOffset):
+        (WebCore::ScrollView::scrollYOffset):
+        (WebCore::ScrollView::inWindow):
+
 2006-03-15  Eric Seidel  <eseidel@apple.com>
 
         Reviewed by darin.
index 4d73f174a80da10dbce57c7ce2f121f097ab7c7a..4435d3e8eeb326d9d2919ce48e57f42617bcb444 100644 (file)
@@ -153,7 +153,7 @@ public:
     virtual void restoreDocumentState();
     
     virtual void addMessageToConsole(const DOMString& message,  unsigned int lineNumber, const DOMString& sourceID);
-    void setDisplaysWithFocusAttributes(bool flag);
+    virtual void setDisplaysWithFocusAttributes(bool flag);
     
     NSView *nextKeyView(NodeImpl *startingPoint, KWQSelectionDirection);
     NSView *nextKeyViewInFrameHierarchy(NodeImpl *startingPoint, KWQSelectionDirection);
@@ -186,7 +186,6 @@ public:
 
     virtual QString mimeTypeForFileName(const QString &) const;
 
-    NSRect visibleSelectionRect() const;
     NSImage *selectionImage() const;
     NSImage *snapshotDragImage(NodeImpl *node, NSRect *imageRect, NSRect *elementRect) const;
 
index 75be624664ec9bef08434f3b79bf2fad59cd5683..6a36b8e7e35f4b6309dc46c6c90056b63b60fac7 100644 (file)
@@ -31,6 +31,7 @@
 #import "Cursor.h"
 #import "DOMInternal.h"
 #import "EventNames.h"
+#import "FloatRect.h"
 #import "FoundationExtras.h"
 #import "FramePrivate.h"
 #import "FrameView.h"
@@ -2681,25 +2682,11 @@ NSAttributedString *MacFrame::attributedString(NodeImpl *_start, int startOffset
     return nil;
 }
 
-// returns NSRect because going through IntRect would truncate any floats
-NSRect MacFrame::visibleSelectionRect() const
-{
-    if (!d->m_view) {
-        return NSZeroRect;
-    }
-    NSView *documentView = d->m_view->getDocumentView();
-    if (!documentView) {
-        return NSZeroRect;
-    }
-    return NSIntersectionRect(selectionRect(), [documentView visibleRect]);     
-}
-
 NSImage *MacFrame::imageFromRect(NSRect rect) const
 {
     NSView *view = d->m_view->getDocumentView();
-    if (!view) {
+    if (!view)
         return nil;
-    }
     
     NSImage *resultImage;
     KWQ_BLOCK_EXCEPTIONS;
@@ -2940,43 +2927,17 @@ void MacFrame::setDisplaysWithFocusAttributes(bool flag)
 {
     if (d->m_isFocused == flag)
         return;
-        
-    d->m_isFocused = flag;
-
-    // This method does the job of updating the view based on whether the view is "active".
-    // This involves four kinds of drawing updates:
-
-    // 1. The background color used to draw behind selected content (active | inactive color)
-    if (d->m_view)
-        d->m_view->updateContents(enclosingIntRect(visibleSelectionRect()));
-
-    // 2. Caret blinking (blinks | does not blink)
-    if (flag)
-        setSelectionFromNone();
-    setCaretVisible(flag);
     
-    // 3. The drawing of a focus ring around links in web pages.
+    Frame::setDisplaysWithFocusAttributes(flag);
     DocumentImpl *doc = document();
-    if (doc) {
-        NodeImpl *node = doc->focusNode();
-        if (node) {
-            node->setChanged();
-            if (node->renderer() && node->renderer()->style()->hasAppearance())
-                theme()->stateChanged(node->renderer(), FocusState);
-        }
-    }
-    
-    // 4. Changing the tint of controls from clear to aqua/graphite and vice versa.  We
+    // Mac Specific: Changing the tint of controls from clear to aqua/graphite and vice versa.  We
     // do a "fake" paint.  When the theme gets a paint call, it can then do an invalidate.
-    if (theme()->supportsControlTints()) {
-        NSView *documentView = d->m_view ? d->m_view->getDocumentView() : 0;
-        if (documentView && renderer()) {
-            doc->updateLayout(); // Ensure layout is up to date.
-            IntRect visibleRect(enclosingIntRect([documentView visibleRect]));
-            GraphicsContext p;
-            p.setUpdatingControlTints(true);
-            paint(&p, visibleRect);
-        }
+    if (doc && d->m_view && d->m_view->getDocumentView() && theme()->supportsControlTints() && renderer()) {
+        doc->updateLayout(); // Ensure layout is up to date.
+        IntRect visibleRect(enclosingIntRect(d->m_view->visibleContentRect()));
+        GraphicsContext p;
+        p.setUpdatingControlTints(true);
+        paint(&p, visibleRect);
     }
 }
 
@@ -2984,9 +2945,8 @@ NSColor *MacFrame::bodyBackgroundColor() const
 {
     if (document() && document()->body() && document()->body()->renderer()) {
         Color bgColor = document()->body()->renderer()->style()->backgroundColor();
-        if (bgColor.isValid()) {
+        if (bgColor.isValid())
             return nsColor(bgColor);
-        }
     }
     return nil;
 }
index 4648e955da6c70e99ca097d6ce7b275716c6702c..20ebe33491ad0eb0f791a74e580fcdf2a0bf683f 100644 (file)
@@ -39,6 +39,7 @@
 #import "CharsetNames.h"
 #import "KWQClipboard.h"
 #import "KWQEditCommand.h"
+#import "FloatRect.h"
 #import "Font.h"
 #import "FoundationExtras.h"
 #import "KWQLoader.h"
index 068e11d9968fac945e664eff16228358dfeaafe4..242b268dd75bb7c96fff4b2df70d95e40c952a9f 100644 (file)
@@ -36,6 +36,7 @@
 #include "DocLoader.h"
 #include "EditingTextImpl.h"
 #include "EventNames.h"
+#include "FloatRect.h"
 #include "Frame.h"
 #include "FrameView.h"
 #include "GraphicsContext.h"
@@ -72,6 +73,7 @@
 #include "render_canvas.h"
 #include "render_frames.h"
 #include "render_layer.h"
+#include "render_theme.h"
 #include "visible_text.h"
 #include "visible_units.h"
 #include "xml_tokenizer.h"
@@ -2540,6 +2542,15 @@ IntRect Frame::selectionRect() const
     return root->selectionRect();
 }
 
+// returns FloatRect because going through IntRect would truncate any floats
+FloatRect Frame::visibleSelectionRect() const
+{
+    if (!d->m_view)
+        return FloatRect();
+    
+    return intersection(selectionRect(), d->m_view->visibleContentRect());
+}
+
 bool Frame::isFrameSet() const
 {
     DocumentImpl* document = d->m_doc.get();
@@ -3170,6 +3181,37 @@ bool Frame::displaysWithFocusAttributes() const
     return d->m_isFocused;
 }
 
+void Frame::setDisplaysWithFocusAttributes(bool flag)
+{
+    if (d->m_isFocused == flag)
+        return;
+    
+    d->m_isFocused = flag;
+
+    // This method does the job of updating the view based on whether the view is "active".
+    // This involves three kinds of drawing updates:
+
+    // 1. The background color used to draw behind selected content (active | inactive color)
+    if (d->m_view)
+        d->m_view->updateContents(enclosingIntRect(visibleSelectionRect()));
+
+    // 2. Caret blinking (blinks | does not blink)
+    if (flag)
+        setSelectionFromNone();
+    setCaretVisible(flag);
+    
+    // 3. The drawing of a focus ring around links in web pages.
+    DocumentImpl *doc = document();
+    if (doc) {
+        NodeImpl *node = doc->focusNode();
+        if (node) {
+            node->setChanged();
+            if (node->renderer() && node->renderer()->style()->hasAppearance())
+                theme()->stateChanged(node->renderer(), FocusState);
+        }
+    }
+}
+
 void Frame::setWindowHasFocus(bool flag)
 {
     if (m_windowHasFocus == flag)
index d33ad9acddce28f9119658bafb060de28a7b628a..284cd9d0f75df9d8c862087341c920536cb62671 100644 (file)
@@ -700,6 +700,7 @@ private:
   RenderPart* ownerRenderer();
 
   IntRect selectionRect() const;
+  FloatRect visibleSelectionRect() const;
   bool isFrameSet() const;
 
   HTMLFormElementImpl *currentForm() const;
@@ -754,6 +755,7 @@ private:
   static void clearTimers(FrameView *);
 
   bool displaysWithFocusAttributes() const;
+  virtual void setDisplaysWithFocusAttributes(bool flag);
   void setWindowHasFocus(bool flag);
   // Convenience, to avoid repeating the code to dig down to get this.
 
index b684c78ebb907d57c1ccfa30353f603c99666b43..3810f8242e144e18a1aaf5b6044803764d91e69f 100644 (file)
 
 #include "ScrollBarMode.h"
 #include "Widget.h"
-#include "IntRect.h"
 
 namespace WebCore {
+    class FloatRect;
 
     class ScrollView : public Widget {
     public:
         int visibleWidth() const;
         int visibleHeight() const;
+        FloatRect visibleContentRect() const;
         int contentsWidth() const;
         int contentsHeight() const;
         int contentsX() const;
index e69c4fdf235a5cce448cee2c8f0855438b811496..b861128180bae81b7f7a1fb19949555dd175b8ae 100644 (file)
@@ -26,6 +26,7 @@
 #import "config.h"
 #import "ScrollView.h"
 
+#import "FloatRect.h"
 #import "IntRect.h"
 #import "KWQExceptions.h"
 #import "Logging.h"
@@ -53,11 +54,10 @@ int ScrollView::visibleWidth() const
     NSScrollView *view = (NSScrollView *)getView();
 
     KWQ_BLOCK_EXCEPTIONS;
-    if ([view isKindOfClass:[NSScrollView class]]) {
+    if ([view isKindOfClass:[NSScrollView class]])
         return (int)[view documentVisibleRect].size.width;
-    } else {
+    else
         return (int)[view bounds].size.width;
-    }
     KWQ_UNBLOCK_EXCEPTIONS;
 
     return 0;
@@ -68,27 +68,34 @@ int ScrollView::visibleHeight() const
     NSScrollView *view = (NSScrollView *)getView();
     
     KWQ_BLOCK_EXCEPTIONS;
-    if ([view isKindOfClass:[NSScrollView class]]) {
+    if ([view isKindOfClass:[NSScrollView class]])
         return (int)[view documentVisibleRect].size.height;
-    } else {
+    else
         return (int)[view bounds].size.height;
-    }
     KWQ_UNBLOCK_EXCEPTIONS;
     
     return 0;
 }
 
+FloatRect ScrollView::visibleContentRect() const
+{
+    KWQ_BLOCK_EXCEPTIONS;
+    if (NSView *docView = getDocumentView())
+        return [docView visibleRect];
+    KWQ_UNBLOCK_EXCEPTIONS;
+    return FloatRect();
+}
+
 int ScrollView::contentsWidth() const
 {
     NSView *docView, *view = getView();
     docView = getDocumentView();
 
     KWQ_BLOCK_EXCEPTIONS;
-    if (docView) {
+    if (docView)
         return (int)[docView bounds].size.width;
-    } else {
+    else
         return (int)[view bounds].size.width;
-    }
     KWQ_UNBLOCK_EXCEPTIONS;
 
     return 0;
@@ -100,11 +107,10 @@ int ScrollView::contentsHeight() const
     docView = getDocumentView();
 
     KWQ_BLOCK_EXCEPTIONS;
-    if (docView) {
+    if (docView)
         return (int)[docView bounds].size.height;
-    } else {
+    else
         return (int)[view bounds].size.height;
-    }
     KWQ_UNBLOCK_EXCEPTIONS;
 
     return 0;
@@ -115,11 +121,10 @@ int ScrollView::contentsX() const
     NSView *view = getView();
 
     KWQ_BLOCK_EXCEPTIONS;
-    if ([view isKindOfClass:[NSScrollView class]]) {
+    if ([view isKindOfClass:[NSScrollView class]])
         return (int)[(NSScrollView *)view documentVisibleRect].origin.x;
-    } else {
+    else
         return (int)[view visibleRect].origin.x;
-    }
     KWQ_UNBLOCK_EXCEPTIONS;
 
     return 0;
@@ -130,11 +135,10 @@ int ScrollView::contentsY() const
     NSView *view = getView();
 
     KWQ_BLOCK_EXCEPTIONS;
-    if ([view isKindOfClass:[NSScrollView class]]) {
+    if ([view isKindOfClass:[NSScrollView class]])
         return (int)[(NSScrollView *)view documentVisibleRect].origin.y;
-    } else {
+    else
         return (int)[view visibleRect].origin.y;
-    }
     KWQ_UNBLOCK_EXCEPTIONS;
 
     return 0;
@@ -145,9 +149,8 @@ int ScrollView::scrollXOffset() const
     NSView *view = getView();
     
     KWQ_BLOCK_EXCEPTIONS;
-    if ([view isKindOfClass:[NSScrollView class]]) {
+    if ([view isKindOfClass:[NSScrollView class]])
         return (int)[[(NSScrollView *)view contentView] visibleRect].origin.x;
-    }
     KWQ_UNBLOCK_EXCEPTIONS;
     return 0;
 }
@@ -157,9 +160,8 @@ int ScrollView::scrollYOffset() const
     NSView *view = getView();
     
     KWQ_BLOCK_EXCEPTIONS;
-    if ([view isKindOfClass:[NSScrollView class]]) {
+    if ([view isKindOfClass:[NSScrollView class]])
         return (int)[[(NSScrollView *)view contentView] visibleRect].origin.y;
-    }
     KWQ_UNBLOCK_EXCEPTIONS;
     return 0;
 }
@@ -442,8 +444,7 @@ NSView *ScrollView::getDocumentView() const
 
 bool ScrollView::inWindow() const
 {
-    NSView* view = getView();
-    return [view window];
+    return [getView() window];
 }
 
 }