summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/WebCore/platform/graphics/android/GLExtras.cpp37
-rw-r--r--Source/WebCore/platform/graphics/android/GLExtras.h7
-rw-r--r--Source/WebKit/Android.mk1
-rw-r--r--Source/WebKit/android/jni/WebViewCore.cpp14
-rw-r--r--Source/WebKit/android/nav/DrawExtra.cpp95
-rw-r--r--Source/WebKit/android/nav/DrawExtra.h33
-rw-r--r--Source/WebKit/android/nav/SelectText.cpp34
-rw-r--r--Source/WebKit/android/nav/SelectText.h24
8 files changed, 149 insertions, 96 deletions
diff --git a/Source/WebCore/platform/graphics/android/GLExtras.cpp b/Source/WebCore/platform/graphics/android/GLExtras.cpp
index 37f598e..b872951 100644
--- a/Source/WebCore/platform/graphics/android/GLExtras.cpp
+++ b/Source/WebCore/platform/graphics/android/GLExtras.cpp
@@ -52,10 +52,6 @@
// Touch ring border width. This is doubled if the ring is not pressed
#define RING_BORDER_WIDTH 1
-// Color of the ring copied from framework's holo_light
-#define COLOR_HOLO_LIGHT 0xFF33b5e5, .4f
-// Color of the ring copied from framework's holo_dark
-#define COLOR_HOLO_DARK 0xFF0099cc, .4f
// Put a cap on the number of matches to draw. If the current page has more
// matches than this, only draw the focused match. This both prevents clutter
// on the page and keeps the performance happy
@@ -73,8 +69,7 @@ GLExtras::~GLExtras()
{
}
-void GLExtras::drawRing(SkRect& srcRect, Color color, float alpha,
- const TransformationMatrix* drawMat)
+void GLExtras::drawRing(SkRect& srcRect, Color color, const TransformationMatrix* drawMat)
{
if (srcRect.fRight <= srcRect.fLeft || srcRect.fBottom <= srcRect.fTop) {
// Invalid rect, reject it
@@ -82,16 +77,20 @@ void GLExtras::drawRing(SkRect& srcRect, Color color, float alpha,
}
XLOG("drawQuad [%fx%f, %f, %f]", srcRect.fLeft, srcRect.fTop,
srcRect.width(), srcRect.height());
+ // Pull the alpha out of the color so that the shader applies it correctly.
+ // Otherwise we either don't have blending enabled, or the alpha will get
+ // double applied
+ Color colorWithoutAlpha(0xFF000000 | color.rgb());
+ float alpha = color.alpha() / (float) 255;
if (drawMat) {
TilesManager::instance()->shader()->drawLayerQuad(*drawMat, srcRect, 0,
- alpha, false, 0, color);
+ alpha, false, 0, colorWithoutAlpha);
} else
- TilesManager::instance()->shader()->drawQuad(srcRect, 0, alpha, color);
+ TilesManager::instance()->shader()->drawQuad(srcRect, 0, alpha, colorWithoutAlpha);
}
-void GLExtras::drawRegion(const SkRegion& region, bool fill,
- bool drawBorder, const TransformationMatrix* drawMat,
- bool useDark)
+void GLExtras::drawRegion(const SkRegion& region, bool fill, bool drawBorder,
+ const TransformationMatrix* drawMat, Color color)
{
if (region.isEmpty())
return;
@@ -101,10 +100,7 @@ void GLExtras::drawRegion(const SkRegion& region, bool fill,
const SkIRect& ir = rgnIter.rect();
SkRect r;
r.set(ir.fLeft, ir.fTop, ir.fRight, ir.fBottom);
- if (useDark)
- drawRing(r, COLOR_HOLO_DARK, drawMat);
- else
- drawRing(r, COLOR_HOLO_LIGHT, drawMat);
+ drawRing(r, color, drawMat);
rgnIter.next();
}
}
@@ -145,10 +141,7 @@ void GLExtras::drawRegion(const SkRegion& region, bool fill,
clip.setRect(line);
}
r.set(line.fLeft, line.fTop, line.fRight, line.fBottom);
- if (useDark)
- drawRing(r, COLOR_HOLO_DARK, drawMat);
- else
- drawRing(r, COLOR_HOLO_LIGHT, drawMat);
+ drawRing(r, color, drawMat);
if (startRect.isEmpty()) {
startRect.set(line.fLeft, line.fTop, line.fRight, line.fBottom);
}
@@ -174,7 +167,7 @@ void GLExtras::drawCursorRings(const LayerAndroid* layer)
region.op(rect, SkRegion::kUnion_Op);
}
drawRegion(region, m_ring->m_isPressed, !m_ring->m_isButton,
- layer ? layer->drawTransform() : 0, false);
+ layer ? layer->drawTransform() : 0);
}
void GLExtras::drawFindOnPage(const LayerAndroid* layer)
@@ -207,7 +200,7 @@ void GLExtras::drawFindOnPage(const LayerAndroid* layer)
}
if (rect.intersect(m_viewport.fLeft, m_viewport.fTop,
m_viewport.fRight, m_viewport.fBottom))
- drawRegion(region, i == current, false, drawTransform, true);
+ drawRegion(region, i == current, false, drawTransform, COLOR_HOLO_DARK);
#ifdef DEBUG
else
XLOG("Quick rejecting [%dx%d, %d, %d", rect.fLeft, rect.fTop,
@@ -217,7 +210,7 @@ void GLExtras::drawFindOnPage(const LayerAndroid* layer)
else {
if (matchRange.first <= current && current < matchRange.second) {
MatchInfo& info = matches->at(current);
- drawRegion(info.getLocation(), true, false, drawTransform, true);
+ drawRegion(info.getLocation(), true, false, drawTransform, COLOR_HOLO_DARK);
}
}
}
diff --git a/Source/WebCore/platform/graphics/android/GLExtras.h b/Source/WebCore/platform/graphics/android/GLExtras.h
index 09e346c..51ad8d8 100644
--- a/Source/WebCore/platform/graphics/android/GLExtras.h
+++ b/Source/WebCore/platform/graphics/android/GLExtras.h
@@ -27,13 +27,13 @@
#define GLExtras_h
#include "Color.h"
+#include "DrawExtra.h"
#include "SkRect.h"
#include "SkRegion.h"
namespace android {
class FindOnPage;
class CursorRing;
- class DrawExtra;
}
namespace WebCore {
@@ -55,11 +55,10 @@ public:
void setViewport(const SkRect & viewport) { m_viewport = viewport; }
void drawRegion(const SkRegion& region, bool fill, bool drawBorder,
- const TransformationMatrix* drawMat, bool useDark = false);
+ const TransformationMatrix* drawMat, Color color = COLOR_HOLO_LIGHT);
private:
- void drawRing(SkRect& srcRect, Color color, float alpha,
- const TransformationMatrix* drawMat);
+ void drawRing(SkRect& srcRect, Color color, const TransformationMatrix* drawMat);
void drawCursorRings(const LayerAndroid* layer);
void drawFindOnPage(const LayerAndroid* layer);
diff --git a/Source/WebKit/Android.mk b/Source/WebKit/Android.mk
index 4e834fd..ee7f3ce 100644
--- a/Source/WebKit/Android.mk
+++ b/Source/WebKit/Android.mk
@@ -88,6 +88,7 @@ LOCAL_SRC_FILES += \
android/nav/CachedLayer.cpp \
android/nav/CachedNode.cpp \
android/nav/CachedRoot.cpp \
+ android/nav/DrawExtra.cpp \
android/nav/FindCanvas.cpp \
android/nav/SelectText.cpp \
android/nav/WebView.cpp \
diff --git a/Source/WebKit/android/jni/WebViewCore.cpp b/Source/WebKit/android/jni/WebViewCore.cpp
index 43b0f1d..fd1a833 100644
--- a/Source/WebKit/android/jni/WebViewCore.cpp
+++ b/Source/WebKit/android/jni/WebViewCore.cpp
@@ -1811,20 +1811,10 @@ SelectText* WebViewCore::createSelectText(const VisibleSelection& selection)
int startOffset = node == startContainer ? range->startOffset() : 0;
int endOffset = node == endContainer ? range->endOffset() : numeric_limits<int>::max();
LayerAndroid* layer = 0;
- int layerId = platformLayerIdFromNode(node, &layer);
- SkRegion* region = selectTextContainer->getHightlightRegionsForLayer(layerId);
- bool needsSet = false;
- if (!region)
- selectTextContainer->setHighlightRegionsForLayer(layerId, region = new SkRegion());
+ platformLayerIdFromNode(node, &layer);
Vector<IntRect> rects;
renderText->absoluteRectsForRange(rects, startOffset, endOffset, true);
- IntPoint offset;
- layerToAbsoluteOffset(layer, offset);
- for (size_t i = 0; i < rects.size(); i++) {
- IntRect& r = rects.at(i);
- r.move(-offset.x(), -offset.y());
- region->op(r.x(), r.y(), r.maxX(), r.maxY(), SkRegion::kUnion_Op);
- }
+ selectTextContainer->addHighlightRegion(layer, rects);
}
IntRect caretRect;
diff --git a/Source/WebKit/android/nav/DrawExtra.cpp b/Source/WebKit/android/nav/DrawExtra.cpp
new file mode 100644
index 0000000..aa8feba
--- /dev/null
+++ b/Source/WebKit/android/nav/DrawExtra.cpp
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "DrawExtra.h"
+#include "GLExtras.h"
+#include "LayerAndroid.h"
+#include "SkCanvas.h"
+#include "SkRegion.h"
+#include "WebViewCore.h"
+
+RegionLayerDrawExtra::RegionLayerDrawExtra()
+ : m_highlightColor(COLOR_HOLO_LIGHT)
+{}
+
+RegionLayerDrawExtra::~RegionLayerDrawExtra()
+{
+ HighlightRegionMap::iterator end = m_highlightRegions.end();
+ for (HighlightRegionMap::iterator it = m_highlightRegions.begin(); it != end; ++it) {
+ delete it->second;
+ it->second = 0;
+ }
+}
+
+SkRegion* RegionLayerDrawExtra::getHightlightRegionsForLayer(const LayerAndroid* layer)
+{
+ int layerId = layer ? layer->uniqueId() : 0;
+ return m_highlightRegions.get(layerId);
+}
+
+void RegionLayerDrawExtra::addHighlightRegion(const LayerAndroid* layer, const Vector<IntRect>& rects)
+{
+ if (rects.isEmpty())
+ return;
+ int layerId = layer ? layer->uniqueId() : 0;
+ SkRegion* region = m_highlightRegions.get(layerId);
+ if (!region) {
+ region = new SkRegion();
+ m_highlightRegions.set(layerId, region);
+ }
+ IntPoint offset;
+ WebViewCore::layerToAbsoluteOffset(layer, offset);
+ for (size_t i = 0; i < rects.size(); i++) {
+ IntRect r = rects.at(i);
+ r.move(-offset.x(), -offset.y());
+ region->op(r.x(), r.y(), r.maxX(), r.maxY(), SkRegion::kUnion_Op);
+ }
+}
+
+void RegionLayerDrawExtra::draw(SkCanvas* canvas, LayerAndroid* layer)
+{
+ SkRegion* region = getHightlightRegionsForLayer(layer);
+ if (!region || region->isEmpty())
+ return;
+ SkRegion::Iterator rgnIter(*region);
+ SkPaint paint;
+ paint.setColor(m_highlightColor.rgb());
+ while (!rgnIter.done()) {
+ const SkIRect& rect = rgnIter.rect();
+ canvas->drawIRect(rect, paint);
+ rgnIter.next();
+ }
+}
+
+void RegionLayerDrawExtra::drawGL(GLExtras* glExtras, const LayerAndroid* layer)
+{
+ SkRegion* region = getHightlightRegionsForLayer(layer);
+ if (!region || region->isEmpty())
+ return;
+ const TransformationMatrix* transform = layer ? layer->drawTransform() : 0;
+ glExtras->drawRegion(*region, true, false, transform, m_highlightColor);
+}
diff --git a/Source/WebKit/android/nav/DrawExtra.h b/Source/WebKit/android/nav/DrawExtra.h
index 27a6598..563e6ac 100644
--- a/Source/WebKit/android/nav/DrawExtra.h
+++ b/Source/WebKit/android/nav/DrawExtra.h
@@ -26,10 +26,23 @@
#ifndef DrawExtra_h
#define DrawExtra_h
+#include "config.h"
+
+#include "Color.h"
+#include "IntPoint.h"
+#include "IntRect.h"
+#include "wtf/HashMap.h"
+#include "wtf/Vector.h"
+
+// Color of the ring copied from framework's holo_light
+#define COLOR_HOLO_LIGHT 0x6633B5E5
+// Color of the ring copied from framework's holo_dark
+#define COLOR_HOLO_DARK 0x660099CC
+
class SkCanvas;
+class SkRegion;
namespace WebCore {
- class IntRect;
class LayerAndroid;
class GLExtras;
}
@@ -46,6 +59,24 @@ public:
virtual void drawGL(GLExtras*, const LayerAndroid*) {}
};
+// A helper extra that has a SkRegion per LayerAndroid
+class RegionLayerDrawExtra : public DrawExtra {
+public:
+ RegionLayerDrawExtra();
+ virtual ~RegionLayerDrawExtra();
+
+ void addHighlightRegion(const LayerAndroid* layer, const Vector<IntRect>& rects);
+ virtual void draw(SkCanvas*, LayerAndroid*);
+ virtual void drawGL(GLExtras*, const LayerAndroid*);
+
+private:
+ SkRegion* getHightlightRegionsForLayer(const LayerAndroid* layer);
+
+ typedef HashMap<int, SkRegion* > HighlightRegionMap;
+ HighlightRegionMap m_highlightRegions;
+ Color m_highlightColor;
+};
+
}
#endif
diff --git a/Source/WebKit/android/nav/SelectText.cpp b/Source/WebKit/android/nav/SelectText.cpp
index b043406..22c67bc 100644
--- a/Source/WebKit/android/nav/SelectText.cpp
+++ b/Source/WebKit/android/nav/SelectText.cpp
@@ -146,40 +146,6 @@ void ReverseBidi(UChar* chars, int len) {
namespace android {
-SelectText::~SelectText()
-{
- HighlightRegionMap::iterator end = m_highlightRegions.end();
- for (HighlightRegionMap::iterator it = m_highlightRegions.begin(); it != end; ++it) {
- delete it->second;
- it->second = 0;
- }
-}
-
-void SelectText::drawGL(GLExtras* extras, const LayerAndroid* layer)
-{
- SkRegion* region = getHightlightRegionsForLayer(layer ? layer->uniqueId() : -1);
- if (!region || region->isEmpty())
- return;
- extras->drawRegion(*region, true, false, layer ? layer->drawTransform() : 0, false);
-}
-
-void SelectText::draw(SkCanvas* canvas, LayerAndroid* layer)
-{
- SkRegion* region = getHightlightRegionsForLayer(layer ? layer->uniqueId() : -1);
- if (!region || region->isEmpty())
- return;
- SkRegion::Iterator rgnIter(*region);
- SkPaint paint;
- paint.setARGB(0x66, 0x33, 0xb5, 0xe5);
- while (!rgnIter.done()) {
- const SkIRect& ir = rgnIter.rect();
- SkRect r;
- r.set(ir.fLeft, ir.fTop, ir.fRight, ir.fBottom);
- canvas->drawRect(r, paint);
- rgnIter.next();
- }
-}
-
SelectText::HandleId SelectText::mapId(HandleId id)
{
if (id == StartHandle || id == EndHandle)
diff --git a/Source/WebKit/android/nav/SelectText.h b/Source/WebKit/android/nav/SelectText.h
index 33d9f3f..904b2b9 100644
--- a/Source/WebKit/android/nav/SelectText.h
+++ b/Source/WebKit/android/nav/SelectText.h
@@ -27,18 +27,12 @@
#define SelectText_h
#include "DrawExtra.h"
-#include "IntPoint.h"
#include "IntRect.h"
#include "PlatformString.h"
-#include "SkPath.h"
-#include "SkPicture.h"
-#include "SkRect.h"
-#include "SkRegion.h"
-#include "wtf/Vector.h"
namespace android {
-class SelectText : public DrawExtra {
+class SelectText : public RegionLayerDrawExtra {
public:
enum HandleId {
StartHandle = 0,
@@ -47,20 +41,6 @@ public:
ExtentHandle = 3,
};
- SelectText() {}
- virtual ~SelectText();
-
- SkRegion* getHightlightRegionsForLayer(int layerId) {
- return m_highlightRegions.get(layerId);
- }
-
- void setHighlightRegionsForLayer(int layerId, SkRegion* region) {
- m_highlightRegions.set(layerId, region);
- }
-
- virtual void draw(SkCanvas*, LayerAndroid*);
- virtual void drawGL(GLExtras*, const LayerAndroid*);
-
IntRect& caretRect(HandleId id) { return m_caretRects[mapId(id)]; }
void setCaretRect(HandleId id, const IntRect& rect) { m_caretRects[mapId(id)] = rect; }
int caretLayerId(HandleId id) { return m_caretLayerId[mapId(id)]; }
@@ -75,8 +55,6 @@ public:
private:
HandleId mapId(HandleId id);
- typedef HashMap<int, SkRegion* > HighlightRegionMap;
- HighlightRegionMap m_highlightRegions;
IntRect m_caretRects[2];
int m_caretLayerId[2];
bool m_baseIsFirst;