All pastes #971019 Raw Edit

Someone

public text v1 · immutable
·published 2008-04-04 13:32 UTC
rendered paste body
==== //depot/qt/4.4/src/3rdparty/webkit/WebCore/page/FrameView.cpp#2 - /home/ben/dev/qt-4.4/src/3rdparty/webkit/WebCore/page/FrameView.cpp ====
@@ -29,6 +29,7 @@
 #include "AXObjectCache.h"
 #include "EventHandler.h"
 #include "FloatRect.h"
+#include "FocusController.h"
 #include "Frame.h"
 #include "FrameLoader.h"
 #include "FrameLoaderClient.h"
@@ -37,11 +38,18 @@
 #include "HTMLFrameSetElement.h"
 #include "HTMLNames.h"
 #include "OverflowEvent.h"
+#include "Page.h"
 #include "RenderPart.h"
 #include "RenderPartObject.h"
 #include "RenderTheme.h"
 #include "RenderView.h"
 
+#if PLATFORM(QT)
+#include "qwebframe.h"
+#include "qwebframe_p.h"
+#include "qwebpage_p.h"
+#endif
+
 namespace WebCore {
 
 using namespace HTMLNames;
@@ -1008,4 +1016,26 @@
 }
 #endif
 
+#if PLATFORM(QT)
+void FrameView::setFocus()
+{
+    // When a node is focused its corresponding frame is also set to active. Then
+    // Document::setFocusedNode calls setFocus() on the FrameView. When the frame is set to active
+    // we paint the caret and the focus frame accordingly. However we should really only do that if
+    // our QWebPage has the focus, otherwise we should reset the frame back to inactive.  When the
+    // QWebPage receives the focus back it'll reactivate the frame, the focus controller remembers
+    // it.
+
+    Frame *f = static_cast<FrameView*>(this)->frame();
+    if (f && f->isActive() && f->page() && f->page()->focusController()->focusedFrame() == f) {
+        ScrollView* topLevel = this->topLevel();
+        if (topLevel && topLevel->isFrameView()) {
+            QWebFrame* qWebFrame = QWebFramePrivate::kit(static_cast<FrameView*>(topLevel)->frame());
+            if (!qWebFrame->page()->d->hasFocus)
+                f->setIsActive(false);
+        }
+    }
+}
+#endif
+
 }
==== //depot/qt/4.4/src/3rdparty/webkit/WebCore/page/FrameView.h#2 - /home/ben/dev/qt-4.4/src/3rdparty/webkit/WebCore/page/FrameView.h ====
@@ -143,6 +143,11 @@
     void layoutIfNeededRecursive();
 #endif
 
+#if PLATFORM(QT)
+    void setFocus();
+#endif
+
+
 private:
     void init();

==== //depot/qt/4.4/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp#40 - /home/ben/dev/qt-4.4/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp ====
@@ -119,6 +119,7 @@
     , view(0)
     , modified(false)
     , viewportSize(QSize(0,0))
+    , hasFocus(false)
 {
     chromeClient = new ChromeClientQt(q);
     contextMenuClient = new ContextMenuClientQt();
@@ -629,14 +630,36 @@
 
 void QWebPagePrivate::focusInEvent(QFocusEvent *ev)
 {
-    if (ev->reason() != Qt::PopupFocusReason)
-        page->focusController()->setFocusedFrame(QWebFramePrivate::core(mainFrame));
+    if (ev->reason() == Qt::PopupFocusReason)
+        return;
+
+    hasFocus = true;
+
+    FocusController *focusController = page->focusController();
+    if (focusController->focusedFrame()) {
+        Frame *frame = focusController->focusedFrame();
+        frame->setIsActive(true);
+        frame->setWindowHasFocus(true);
+    } else {
+        focusController->setFocusedFrame(QWebFramePrivate::core(mainFrame));
+    }
 }
 
 void QWebPagePrivate::focusOutEvent(QFocusEvent *ev)
 {
-    if (ev->reason() != Qt::PopupFocusReason)
-        page->focusController()->setFocusedFrame(0);
+    if (ev->reason() == Qt::PopupFocusReason)
+        return;
+
+    hasFocus = false;
+
+    // only set the focused frame inactive so that we stop painting the caret
+    // and the focus frame. But don't tell the focus controller so that upon
+    // focusInEvent() we can re-activate the frame.
+    Frame *frame = page->focusController()->focusedFrame();
+    if (frame) {
+        frame->setIsActive(false);
+        frame->setWindowHasFocus(false);
+    }
 }
 
 void QWebPagePrivate::dragEnterEvent(QDragEnterEvent *ev)
==== //depot/qt/4.4/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.h#16 - /home/ben/dev/qt-4.4/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.h ====
@@ -54,6 +54,7 @@
     class InspectorClientQt;
     class ResourceHandle;
     class HitTestResult;
+    class FrameView;
 }
 
 class QWEBKIT_EXPORT QWebPage : public QObject
@@ -286,6 +287,7 @@
     friend class WebCore::FrameLoaderClientQt;
     friend class WebCore::InspectorClientQt;
     friend class WebCore::ResourceHandle;
+    friend class WebCore::FrameView;
 };
 
 Q_DECLARE_OPERATORS_FOR_FLAGS(QWebPage::FindFlags)
==== //depot/qt/4.4/src/3rdparty/webkit/WebKit/qt/Api/qwebpage_p.h#13 - /home/ben/dev/qt-4.4/src/3rdparty/webkit/WebKit/qt/Api/qwebpage_p.h ====
@@ -102,6 +102,7 @@
     bool modified;
 
     bool insideOpenCall;
+    bool hasFocus;
     quint64 m_totalBytes;
     quint64 m_bytesReceived;