Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1684)

Unified Diff: webkit/port/platform/graphics/ThemeHelperWin.cpp

Issue 9008: Add support for arbitrarily transformed Windows buttons text field... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/port/platform/graphics/ThemeHelperWin.cpp
===================================================================
--- webkit/port/platform/graphics/ThemeHelperWin.cpp (revision 0)
+++ webkit/port/platform/graphics/ThemeHelperWin.cpp (revision 0)
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2008 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "FloatRect.h"
+#include "GraphicsContext.h"
+#include "ThemeHelperWin.h"
+
+namespace WebCore {
+
+static void IntRectToRECT(const IntRect& ir, RECT* r)
M-A Ruel 2008/11/03 20:18:46 I guess we can't use operator RECT() because it's
+{
+ r->left = ir.x();
+ r->top = ir.y();
+ r->right = ir.right();
+ r->bottom = ir.bottom();
+}
+
+ThemeHelperWin::ThemeHelperWin(GraphicsContext* context,
+ const IntRect& rect)
+ : m_orgContext(context)
+ , m_orgMatrix(context->getCTM())
+ , m_orgRect(rect)
+{
+ if (m_orgMatrix.b() != 0 || // Y skew
+ m_orgMatrix.c() != 0) { // X skew
+ // Complicated effects, make a copy and draw the bitmap there.
+ m_type = COPY;
+ m_rect.left = 0;
+ m_rect.top = 0;
+ m_rect.right = rect.width();
+ m_rect.bottom = rect.height();
+
+ m_newBuffer.set(ImageBuffer::create(rect.size(), false).release());
+
+ // Theme drawing messes with the transparency.
+ // TODO(brettw) Ideally, we would leave this transparent, but I was
+ // having problems with button drawing, so we fill with white. Buttons
+ // looked good with transparent here and no fixing up of the alpha
+ // later, but text areas didn't. This makes text areas look good but
+ // gives buttons a white halo. Is there a way to fix this? I think
+ // buttons actually have antialised edges which is just not possible
+ // to handle on a transparent background given that it messes with the
+ // alpha channel.
+ FloatRect newContextRect(0, 0, rect.width(), rect.height());
+ GraphicsContext* newContext = m_newBuffer->context();
+ newContext->setFillColor(Color::white);
+ newContext->fillRect(newContextRect);
+
+ return;
+ }
+
+ if (m_orgMatrix.a() != 1.0 || // X scale
+ m_orgMatrix.d() != 1.0) { // Y scale
+ // Only a scaling is applied.
+ m_type = SCALE;
+
+ // Save the transformed coordinates to draw.
+ IntRectToRECT(m_orgMatrix.mapRect(rect), &m_rect);
+
+ m_orgContext->save();
+ m_orgContext->concatCTM(m_orgContext->getCTM().inverse());
+ return;
+ }
+
+ // Nothing interesting.
+ IntRectToRECT(rect, &m_rect);
+ m_type = ORIGINAL;
+}
+
+ThemeHelperWin::~ThemeHelperWin()
+{
+ switch (m_type) {
+ case SCALE:
+ m_orgContext->restore();
+ break;
+ case COPY: {
+ // Copy the duplicate bitmap with our control to the original canvas.
+ FloatRect destRect(m_orgRect);
+ m_newBuffer->context()->platformContext()->canvas()->
+ getTopPlatformDevice().fixupAlphaBeforeCompositing();
+ m_orgContext->drawImage(m_newBuffer->image(), destRect);
+ break;
+ }
+ case ORIGINAL:
+ break;
+ }
+}
+
+RECT ThemeHelperWin::transformRect(const RECT& r) const
+{
+ IntRect src(r.left, r.top, r.right - r.left, r.bottom - r.top);
+ IntRect dest;
+ switch (m_type) {
+ case SCALE:
+ dest = m_orgMatrix.mapRect(src);
+ break;
+ case COPY:
+ dest = src;
+ dest.move(-m_orgRect.x(), -m_orgRect.y());
+ break;
+ case ORIGINAL:
+ break;
+ }
+
+ RECT output;
+ IntRectToRECT(dest, &output);
+ return output;
+}
+
+} // namespace WebCore
Property changes on: webkit\port\platform\graphics\ThemeHelperWin.cpp
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698