1f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)/*
2f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * Copyright (C) 2013 Google Inc. All Rights Reserved.
3f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) *
4f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
5f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * modification, are permitted provided that the following conditions
6f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * are met:
7f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright
8f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer.
9f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright
10f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer in the
11f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) *    documentation and/or other materials provided with the distribution.
12f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) *
13f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY GOOGLE, INC. ``AS IS'' AND ANY
14f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) *
25f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) */
26f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)
27f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "config.h"
28a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/OverscrollTheme.h"
29f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)
30c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
31f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)
32f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)OverscrollTheme::OverscrollTheme()
33f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){
34f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#if USE(RUBBER_BANDING)
35f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    // Load the shadow and pattern for the overhang.
36f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    m_overhangShadow = Image::loadPlatformResource("overhangShadow");
37f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    m_overhangPattern = Image::loadPlatformResource("overhangPattern");
38f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#endif
39f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)}
40f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)
41f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)PassRefPtr<Image> OverscrollTheme::getOverhangImage()
42f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){
43f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    return m_overhangPattern;
44f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)}
45f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)
46f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void OverscrollTheme::setUpOverhangShadowLayer(GraphicsLayer* overhangShadowLayer)
47f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){
48f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    // The shadow texture is has a 1-pixel aperture in the center, so the division by
49f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    // two is doing an intentional round-down.
50f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    overhangShadowLayer->setContentsToNinePatch(
51f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)        m_overhangShadow.get(),
52f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)        IntRect(m_overhangShadow->width() / 2, m_overhangShadow->height() / 2, 1, 1));
53f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)}
54f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)
55f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void OverscrollTheme::updateOverhangShadowLayer(GraphicsLayer* shadowLayer, GraphicsLayer* rootContentLayer)
56f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){
57f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    // Note that for the position, the division m_overhangShadow->width() / 2 is an intentional
58f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    // round-down, and that for the width and height, the 1-pixel aperture is being replaced
59f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    // by the root contents layer, hence subtracting 1 and adding the rootContentsLayer size.
60f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    IntRect shadowRect(
61f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)        static_cast<int>(rootContentLayer->position().x()) - m_overhangShadow->width() / 2,
62f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)        static_cast<int>(rootContentLayer->position().y()) -  m_overhangShadow->height() / 2,
63f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)        static_cast<int>(rootContentLayer->size().width()) + m_overhangShadow->width() - 1,
64f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)        static_cast<int>(rootContentLayer->size().height()) + m_overhangShadow->height() - 1);
65f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    shadowLayer->setContentsRect(shadowRect);
66f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)}
67f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)
68f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)OverscrollTheme* OverscrollTheme::theme()
69f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){
70f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    DEFINE_STATIC_LOCAL(OverscrollTheme, theme, ());
71f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    return &theme;
72f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)}
73f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)
74f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)}
75