From 9364f22aed35e1a1e9d07c121510f80be3ab0502 Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Tue, 21 Oct 2008 07:00:00 -0700 Subject: Initial Contribution --- .../graphics/android/PlatformGraphicsContext.cpp | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 WebCore/platform/graphics/android/PlatformGraphicsContext.cpp (limited to 'WebCore/platform/graphics/android/PlatformGraphicsContext.cpp') diff --git a/WebCore/platform/graphics/android/PlatformGraphicsContext.cpp b/WebCore/platform/graphics/android/PlatformGraphicsContext.cpp new file mode 100644 index 0000000..af443b8 --- /dev/null +++ b/WebCore/platform/graphics/android/PlatformGraphicsContext.cpp @@ -0,0 +1,73 @@ +/* + * + * Copyright 2006, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "config.h" +#include "Node.h" +#include "PlatformGraphicsContext.h" +#include "SkCanvas.h" + +namespace WebCore { + +PlatformGraphicsContext::PlatformGraphicsContext(SkCanvas* canvas) : mCanvas(canvas), m_deleteCanvas(false) +{ + // This is useful only if this Canvas is part of an SkPicture object. + m_buttons = new SkTDArray; +} + +PlatformGraphicsContext::PlatformGraphicsContext() : m_deleteCanvas(true) +{ + mCanvas = new SkCanvas; + // Since this is our own private SkCanvas, and has no relation to a picture + // storing button references would be meaningless. + m_buttons = NULL; +} + +PlatformGraphicsContext::~PlatformGraphicsContext() +{ + if (m_deleteCanvas) { +// printf("-------------------- deleting offscreen canvas\n"); + delete mCanvas; + } + if (m_buttons != NULL) { + m_buttons->deleteAll(); + delete m_buttons; + } +} + +SkTDArray* PlatformGraphicsContext::getAndClearButtonInfo() +{ + // The caller is now responsible for deleting the array + SkTDArray* buttons = m_buttons; + m_buttons = NULL; + return buttons; +} + +void PlatformGraphicsContext::storeButtonInfo(Node* node, const IntRect& r) +{ + if (m_buttons == NULL) + return; + // Initialize all of the nodes to have disabled state, so that we guarantee + // that we paint all of them the first time. + RenderSkinAndroid::State state = RenderSkinAndroid::kDisabled; + Container* container = new Container(node, r, state); + // Place a reference to our subpicture in the Picture. + mCanvas->drawPicture(*(container->picture())); + // Keep track of the information about the button. + *m_buttons->append() = container; +} + +} // WebCore -- cgit v1.1