diff options
author | finnur@google.com <finnur@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-24 23:46:50 +0000 |
---|---|---|
committer | finnur@google.com <finnur@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-24 23:46:50 +0000 |
commit | 884db41554423ec017c57709f92cc2379e0cc02d (patch) | |
tree | 275e81e0c6ab0717912dd4864d91ad719bd2a55c /webkit/port | |
parent | 498c1a6b2dc98869e0703127565247830227d075 (diff) | |
download | chromium_src-884db41554423ec017c57709f92cc2379e0cc02d.zip chromium_src-884db41554423ec017c57709f92cc2379e0cc02d.tar.gz chromium_src-884db41554423ec017c57709f92cc2379e0cc02d.tar.bz2 |
Find now uses WebKit's TextMatch highlighting for Find-in-page.
This allows us to discard a bunch of code and plumbing related to
maintaining and passing around the tickmark vector.
WebKit now owns the drawing of the highlights for inactive matches and
we use the selection controller to draw the active highlight.
I also simplified the code by eliminating the separate FindNext
function, which has been merged into Find.
This change also requires minor changes to WebKit upstream (sold
seperately, void where prohibited).
It simply consists of adding one empty virtual paint function to
ScrollbarThemeComposite.h (paintTickmarks) and in
ScrollbarThemeComposite::paint call paintTickmarks().
This fixes/makes obsolete a slew of bugs:
BUG=1326399, 1241554,1143991, 1070190, 1023019, 984786, 893737, 868599
... and a couple of external ones as well. Full list:
1326399 Find highlighting disappears on ThinkPad x60s
1241554 Find doesn't highlight word inside blinky tag
1143991 Have find-in-page code use skia and have inspected node highlighting set the right xfermode
1070190 Find should begin searching from caret/selection
1023019 Find not highlighting correctly
984786 Find highlight drawing code causes ClearType text to look bad
893737 Find in page should search textareas
868599 Find in page tick marks incorrectly appear on nested scrollbars
298 Find-In-page should highlight elided entries
4389 Find-in-box is not highlighting all the instances of the search word
3908 Find in page highlighting and tickmarks are broken
Review URL: http://codereview.chromium.org/11364
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5946 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/port')
-rw-r--r-- | webkit/port/platform/chromium/ScrollbarThemeChromium.cpp | 45 | ||||
-rw-r--r-- | webkit/port/platform/chromium/ScrollbarThemeChromium.h | 1 | ||||
-rw-r--r-- | webkit/port/rendering/RenderThemeWin.cpp | 26 | ||||
-rw-r--r-- | webkit/port/rendering/RenderThemeWin.h | 7 |
4 files changed, 76 insertions, 3 deletions
diff --git a/webkit/port/platform/chromium/ScrollbarThemeChromium.cpp b/webkit/port/platform/chromium/ScrollbarThemeChromium.cpp index 0cbf018..f9d961c 100644 --- a/webkit/port/platform/chromium/ScrollbarThemeChromium.cpp +++ b/webkit/port/platform/chromium/ScrollbarThemeChromium.cpp @@ -28,6 +28,8 @@ #include "ChromiumBridge.h" #include "PlatformMouseEvent.h" +#include "Frame.h" +#include "FrameView.h" #include "Scrollbar.h" #include "ScrollbarThemeComposite.h" @@ -112,6 +114,49 @@ void ScrollbarThemeChromium::paintTrackBackground(GraphicsContext* context, Scro paintTrackPiece(context, scrollbar, rect, ForwardTrackPart); } +void ScrollbarThemeChromium::paintTickmarks(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect) +{ + if (scrollbar->orientation() != VerticalScrollbar) + return; + + if (rect.height() <= 0 || rect.width() <= 0) + return; // nothing to draw on. + + // Get the frameview. + // FIXME: Stop relying on high-level WebCore types such as Frame and FrameView. + if (!scrollbar->parent()->isFrameView()) + return; + FrameView* frameView = static_cast<FrameView*>(scrollbar->parent()); + Document* doc = frameView->frame()->document(); + + // Get the text markers for the frameview. + Vector<IntRect> markers = doc->renderedRectsForMarkers(DocumentMarker::TextMatch); + if (!markers.size()) + return; + + // Get the image for the tickmarks. + static RefPtr<Image> dash = Image::loadPlatformResource("tickmarkDash"); + if (dash->isNull()) { + ASSERT_NOT_REACHED(); + return; + } + + context->save(); + + for (Vector<IntRect>::const_iterator i = markers.begin(); i != markers.end(); ++i) { + // Calculate how far down (in %) the tick-mark should appear. + const float percent = static_cast<float>(i->y()) / scrollbar->totalSize(); + + // Calculate how far down (in pixels) the tick-mark should appear. + const int yPos = rect.topLeft().y() + (rect.height() * percent); + + IntPoint tick(scrollbar->x(), yPos); + context->drawImage(dash.get(), tick); + } + + context->restore(); +} + void ScrollbarThemeChromium::paintScrollCorner(ScrollView* view, GraphicsContext* context, const IntRect& cornerRect) { // ScrollbarThemeComposite::paintScrollCorner incorrectly assumes that the diff --git a/webkit/port/platform/chromium/ScrollbarThemeChromium.h b/webkit/port/platform/chromium/ScrollbarThemeChromium.h index f75b052..c198222 100644 --- a/webkit/port/platform/chromium/ScrollbarThemeChromium.h +++ b/webkit/port/platform/chromium/ScrollbarThemeChromium.h @@ -65,6 +65,7 @@ protected: virtual void paintTrackPiece(GraphicsContext*, Scrollbar*, const IntRect&, ScrollbarPart); virtual void paintButton(GraphicsContext*, Scrollbar*, const IntRect&, ScrollbarPart); virtual void paintThumb(GraphicsContext*, Scrollbar*, const IntRect&); + virtual void paintTickmarks(GraphicsContext*, Scrollbar*, const IntRect&); private: IntSize buttonSize(Scrollbar*); diff --git a/webkit/port/rendering/RenderThemeWin.cpp b/webkit/port/rendering/RenderThemeWin.cpp index aa6322b..24f6b20 100644 --- a/webkit/port/rendering/RenderThemeWin.cpp +++ b/webkit/port/rendering/RenderThemeWin.cpp @@ -108,6 +108,8 @@ WebCore::FontDescription labelFont; namespace WebCore { +bool RenderThemeWin::m_findInPageMode = false; + // Internal static helper functions. We don't put them in an anonymous // namespace so they have easier access to the WebCore namespace. @@ -331,7 +333,9 @@ bool RenderThemeWin::supportsFocusRing(const RenderStyle* style) const Color RenderThemeWin::platformActiveSelectionBackgroundColor() const { if (ChromiumBridge::layoutTestMode()) - return Color("#0000FF"); // Royal blue + return Color("#0000FF"); // Royal blue. + if (m_findInPageMode) + return Color(255, 150, 50, 200); // Orange. COLORREF color = GetSysColor(COLOR_HIGHLIGHT); return Color(GetRValue(color), GetGValue(color), GetBValue(color), 255); } @@ -339,7 +343,9 @@ Color RenderThemeWin::platformActiveSelectionBackgroundColor() const Color RenderThemeWin::platformInactiveSelectionBackgroundColor() const { if (ChromiumBridge::layoutTestMode()) - return Color("#999999"); // Medium grey + return Color("#999999"); // Medium gray. + if (m_findInPageMode) + return Color(255, 150, 50, 200); // Orange. COLORREF color = GetSysColor(COLOR_GRAYTEXT); return Color(GetRValue(color), GetGValue(color), GetBValue(color), 255); } @@ -347,7 +353,7 @@ Color RenderThemeWin::platformInactiveSelectionBackgroundColor() const Color RenderThemeWin::platformActiveSelectionForegroundColor() const { if (ChromiumBridge::layoutTestMode()) - return Color("#FFFFCC"); // Pale yellow + return Color("#FFFFCC"); // Pale yellow. COLORREF color = GetSysColor(COLOR_HIGHLIGHTTEXT); return Color(GetRValue(color), GetGValue(color), GetBValue(color), 255); } @@ -357,6 +363,11 @@ Color RenderThemeWin::platformInactiveSelectionForegroundColor() const return Color::white; } +Color RenderThemeWin::platformTextSearchHighlightColor() const +{ + return Color(255, 255, 150); +} + double RenderThemeWin::caretBlinkFrequency() const { // Disable the blinking caret in layout test mode, as it introduces @@ -872,4 +883,13 @@ int RenderThemeWin::menuListInternalPadding(RenderStyle* style, int paddingType) return padding; } +// static +void RenderThemeWin::setFindInPageMode(bool enable) { + if (m_findInPageMode == enable) + return; + + m_findInPageMode = enable; + theme()->platformColorsDidChange(); +} + } // namespace WebCore diff --git a/webkit/port/rendering/RenderThemeWin.h b/webkit/port/rendering/RenderThemeWin.h index 2ca8c70..9398cfe 100644 --- a/webkit/port/rendering/RenderThemeWin.h +++ b/webkit/port/rendering/RenderThemeWin.h @@ -57,6 +57,7 @@ public: virtual Color platformInactiveSelectionBackgroundColor() const; virtual Color platformActiveSelectionForegroundColor() const; virtual Color platformInactiveSelectionForegroundColor() const; + virtual Color platformTextSearchHighlightColor() const; virtual double caretBlinkFrequency() const; @@ -118,6 +119,9 @@ public: // the value to get it directly from the appropriate Settings object. static void setDefaultFontSize(int); + // Enables/Disables FindInPage mode, which (if enabled) overrides the + // selection rect color to be orange. + static void setFindInPageMode(bool); private: unsigned determineState(RenderObject*); unsigned determineClassicState(RenderObject*); @@ -130,6 +134,9 @@ private: void getMinimalButtonPadding(Length* minXPadding) const; int menuListInternalPadding(RenderStyle* style, int paddingType) const; + + // A flag specifying whether we are in Find-in-page mode or not. + static bool m_findInPageMode; }; } |