Title: [153586] trunk/Source
Revision
153586
Author
[email protected]
Date
2013-08-01 09:23:14 -0700 (Thu, 01 Aug 2013)

Log Message

Rearrange the code of FrameWin
https://bugs.webkit.org/show_bug.cgi?id=117984

Reviewed by Brent Fulgham.

Source/WebCore:

Move code from the CG implementation into the general file so we can
share the code with Windows CE port in a next step. In a first step
it only shares more code between the CG and Cairo implementations.
Also use OwnPtr instead of plain pointers to make ownership more clear.

* page/win/FrameCGWin.cpp:
(WebCore::imageFromRect):
* page/win/FrameCairoWin.cpp:
(WebCore::imageFromRect):
* page/win/FrameWin.cpp:
(WebCore::imageFromSelection):
(WebCore::Frame::dragImageForSelection):
(WebCore::Frame::nodeImage):
* page/win/FrameWin.h:

Source/WebKit/win:

* WebView.cpp:
(WebView::generateSelectionImage):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (153585 => 153586)


--- trunk/Source/WebCore/ChangeLog	2013-08-01 15:35:47 UTC (rev 153585)
+++ trunk/Source/WebCore/ChangeLog	2013-08-01 16:23:14 UTC (rev 153586)
@@ -1,3 +1,25 @@
+2013-08-01  Patrick Gansterer  <[email protected]>
+
+        Rearrange the code of FrameWin
+        https://bugs.webkit.org/show_bug.cgi?id=117984
+
+        Reviewed by Brent Fulgham.
+
+        Move code from the CG implementation into the general file so we can
+        share the code with Windows CE port in a next step. In a first step
+        it only shares more code between the CG and Cairo implementations.
+        Also use OwnPtr instead of plain pointers to make ownership more clear.
+
+        * page/win/FrameCGWin.cpp:
+        (WebCore::imageFromRect):
+        * page/win/FrameCairoWin.cpp:
+        (WebCore::imageFromRect):
+        * page/win/FrameWin.cpp:
+        (WebCore::imageFromSelection):
+        (WebCore::Frame::dragImageForSelection):
+        (WebCore::Frame::nodeImage):
+        * page/win/FrameWin.h:
+
 2013-08-01  Andrei Parvu  <[email protected]>
 
         mask-repeat: round bug

Modified: trunk/Source/WebCore/page/win/FrameCGWin.cpp (153585 => 153586)


--- trunk/Source/WebCore/page/win/FrameCGWin.cpp	2013-08-01 15:35:47 UTC (rev 153585)
+++ trunk/Source/WebCore/page/win/FrameCGWin.cpp	2013-08-01 16:23:14 UTC (rev 153586)
@@ -49,7 +49,7 @@
     view->paint(gc, rect);
 }
 
-static HBITMAP imageFromRect(const Frame* frame, IntRect& ir)
+PassOwnPtr<HBITMAP> imageFromRect(const Frame* frame, IntRect& ir)
 {
     PaintBehavior oldPaintBehavior = frame->view()->paintBehavior();
     frame->view()->setPaintBehavior(oldPaintBehavior | PaintBehaviorFlattenCompositingLayers);
@@ -60,8 +60,8 @@
     int h = ir.height();
     BitmapInfo bmp = BitmapInfo::create(IntSize(w, h));
 
-    HBITMAP hbmp = CreateDIBSection(0, &bmp, DIB_RGB_COLORS, static_cast<void**>(&bits), 0, 0);
-    HBITMAP hbmpOld = static_cast<HBITMAP>(SelectObject(hdc, hbmp));
+    OwnPtr<HBITMAP> hbmp = adoptPtr(CreateDIBSection(0, &bmp, DIB_RGB_COLORS, static_cast<void**>(&bits), 0, 0));
+    HGDIOBJ hbmpOld = SelectObject(hdc, hbmp.get());
     CGContextRef context = CGBitmapContextCreate(static_cast<void*>(bits), w, h,
         8, w * sizeof(RGBQUAD), deviceRGBColorSpaceRef(), kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
     CGContextSaveGState(context);
@@ -76,38 +76,7 @@
 
     frame->view()->setPaintBehavior(oldPaintBehavior);
 
-    return hbmp;
+    return hbmp.release();
 }
 
-HBITMAP imageFromSelection(Frame* frame, bool forceBlackText)
-{
-    frame->document()->updateLayout();
-
-    frame->view()->setPaintBehavior(PaintBehaviorSelectionOnly | (forceBlackText ? PaintBehaviorForceBlackText : 0));
-    FloatRect fr = frame->selection()->bounds();
-    IntRect ir(static_cast<int>(fr.x()), static_cast<int>(fr.y()),
-               static_cast<int>(fr.width()), static_cast<int>(fr.height()));
-    HBITMAP image = imageFromRect(frame, ir);
-    frame->view()->setPaintBehavior(PaintBehaviorNormal);
-    return image;
-}
-
-DragImageRef Frame::nodeImage(Node* node)
-{
-    document()->updateLayout();
-
-    RenderObject* renderer = node->renderer();
-    if (!renderer)
-        return 0;
-
-    LayoutRect topLevelRect;
-    IntRect paintingRect = pixelSnappedIntRect(renderer->paintingRootRect(topLevelRect));
-
-    m_view->setNodeToDraw(node); // invoke special sub-tree drawing mode
-    HBITMAP result = imageFromRect(this, paintingRect);
-    m_view->setNodeToDraw(0);
-
-    return result;
-}
-
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/win/FrameCairoWin.cpp (153585 => 153586)


--- trunk/Source/WebCore/page/win/FrameCairoWin.cpp	2013-08-01 15:35:47 UTC (rev 153585)
+++ trunk/Source/WebCore/page/win/FrameCairoWin.cpp	2013-08-01 16:23:14 UTC (rev 153586)
@@ -27,23 +27,14 @@
 #include "Frame.h"
 #include "FrameWin.h"
 
-#include "EditorClient.h"
 #include "NotImplemented.h"
 
-using std::min;
-
 namespace WebCore {
 
-HBITMAP imageFromSelection(Frame* frame, bool forceBlackText)
+PassOwnPtr<HBITMAP> imageFromRect(const Frame*, IntRect&)
 {
     notImplemented();
-    return 0;
+    return nullptr;
 }
 
-DragImageRef Frame::nodeImage(Node*)
-{
-    notImplemented();
-    return 0;
-}
-
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/win/FrameWin.cpp (153585 => 153586)


--- trunk/Source/WebCore/page/win/FrameWin.cpp	2013-08-01 15:35:47 UTC (rev 153585)
+++ trunk/Source/WebCore/page/win/FrameWin.cpp	2013-08-01 16:23:14 UTC (rev 153586)
@@ -26,16 +26,13 @@
 #include "config.h"
 #include "FrameWin.h"
 
-#include "BridgeJSC.h"
 #include "Document.h"
 #include "FloatRect.h"
 #include "Frame.h"
 #include "FrameSelection.h"
+#include "FrameView.h"
 #include "PrintContext.h"
-#include "Range.h"
-#include "RenderView.h"
-#include "Settings.h"
-#include "TransformationMatrix.h"
+#include "RenderObject.h"
 
 namespace WebCore {
 
@@ -48,12 +45,42 @@
     outPages = printContext.pageRects();
 }
 
+PassOwnPtr<HBITMAP> imageFromSelection(Frame* frame, bool forceBlackText)
+{
+    frame->document()->updateLayout();
+
+    frame->view()->setPaintBehavior(PaintBehaviorSelectionOnly | (forceBlackText ? PaintBehaviorForceBlackText : 0));
+    FloatRect fr = frame->selection()->bounds();
+    IntRect ir(static_cast<int>(fr.x()), static_cast<int>(fr.y()), static_cast<int>(fr.width()), static_cast<int>(fr.height()));
+    OwnPtr<HBITMAP> image = imageFromRect(frame, ir);
+    frame->view()->setPaintBehavior(PaintBehaviorNormal);
+    return image.release();
+}
+
 DragImageRef Frame::dragImageForSelection()
-{    
+{
     if (selection()->isRange())
-        return imageFromSelection(this, false);
+        return imageFromSelection(this, false).leakPtr();
 
     return 0;
 }
 
+DragImageRef Frame::nodeImage(Node* node)
+{
+    document()->updateLayout();
+
+    RenderObject* renderer = node->renderer();
+    if (!renderer)
+        return 0;
+
+    LayoutRect topLevelRect;
+    IntRect paintingRect = pixelSnappedIntRect(renderer->paintingRootRect(topLevelRect));
+
+    m_view->setNodeToDraw(node); // invoke special sub-tree drawing mode
+    OwnPtr<HBITMAP> result = imageFromRect(this, paintingRect);
+    m_view->setNodeToDraw(0);
+
+    return result.leakPtr();
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/win/FrameWin.h (153585 => 153586)


--- trunk/Source/WebCore/page/win/FrameWin.h	2013-08-01 15:35:47 UTC (rev 153585)
+++ trunk/Source/WebCore/page/win/FrameWin.h	2013-08-01 16:23:14 UTC (rev 153586)
@@ -26,6 +26,7 @@
 #ifndef FrameWin_h
 #define FrameWin_h
 
+#include <wtf/PassOwnPtr.h>
 #include <wtf/Vector.h>
 
 // Forward declared so we don't need wingdi.h.
@@ -33,12 +34,13 @@
 
 namespace WebCore {
 
-    class Frame;
-    class IntRect;
+class Frame;
+class IntRect;
 
-    HBITMAP imageFromSelection(Frame* frame, bool forceWhiteText);
-    void computePageRectsForFrame(Frame*, const IntRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, Vector<IntRect>& outPages, int& outPageHeight);
+PassOwnPtr<HBITMAP> imageFromRect(const Frame*, IntRect&);
+PassOwnPtr<HBITMAP> imageFromSelection(Frame*, bool forceWhiteText);
+void computePageRectsForFrame(Frame*, const IntRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, Vector<IntRect>& outPages, int& outPageHeight);
 
-}
+} // namespace WebCore
 
-#endif
+#endif // FrameWin_h

Modified: trunk/Source/WebKit/win/ChangeLog (153585 => 153586)


--- trunk/Source/WebKit/win/ChangeLog	2013-08-01 15:35:47 UTC (rev 153585)
+++ trunk/Source/WebKit/win/ChangeLog	2013-08-01 16:23:14 UTC (rev 153586)
@@ -1,3 +1,13 @@
+2013-08-01  Patrick Gansterer  <[email protected]>
+
+        Rearrange the code of FrameWin
+        https://bugs.webkit.org/show_bug.cgi?id=117984
+
+        Reviewed by Brent Fulgham.
+
+        * WebView.cpp:
+        (WebView::generateSelectionImage):
+
 2013-07-25  Andreas Kling  <[email protected]>
 
         ChromeClient::focusedNodeChanged() should be focusedElementChanged().

Modified: trunk/Source/WebKit/win/WebView.cpp (153585 => 153586)


--- trunk/Source/WebKit/win/WebView.cpp	2013-08-01 15:35:47 UTC (rev 153585)
+++ trunk/Source/WebKit/win/WebView.cpp	2013-08-01 16:23:14 UTC (rev 153586)
@@ -3563,8 +3563,8 @@
     WebCore::Frame* frame = m_page->focusController()->focusedOrMainFrame();
 
     if (frame) {
-        HBITMAP bitmap = imageFromSelection(frame, forceWhiteText ? TRUE : FALSE);
-        *hBitmap = (OLE_HANDLE)(ULONG64)bitmap;
+        OwnPtr<HBITMAP> bitmap = imageFromSelection(frame, forceWhiteText ? TRUE : FALSE);
+        *hBitmap = static_cast<OLE_HANDLE>(reinterpret_cast<ULONG64>(bitmap.leakPtr()));
     }
 
     return S_OK;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to