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

Side by Side Diff: Source/web/PageOverlayList.cpp

Issue 1264483002: PageOverlays: Remove PageOverlayList (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 5 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/web/PageOverlayList.h ('k') | Source/web/PageOverlayTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include "config.h"
30 #include "web/PageOverlayList.h"
31
32 #include "public/web/WebPageOverlay.h"
33 #include "web/PageOverlay.h"
34 #include "web/WebViewImpl.h"
35
36 namespace blink {
37
38 PassOwnPtr<PageOverlayList> PageOverlayList::create(WebViewImpl* viewImpl)
39 {
40 return adoptPtr(new PageOverlayList(viewImpl));
41 }
42
43 PageOverlayList::PageOverlayList(WebViewImpl* viewImpl)
44 : m_viewImpl(viewImpl)
45 {
46 }
47
48 PageOverlayList::~PageOverlayList()
49 {
50 }
51
52 bool PageOverlayList::add(WebPageOverlay* overlay, int zOrder)
53 {
54 bool added = false;
55 size_t index = find(overlay);
56 if (index == WTF::kNotFound) {
57 OwnPtr<PageOverlay> pageOverlay = PageOverlay::create(m_viewImpl, overla y);
58 m_pageOverlays.append(pageOverlay.release());
59 index = m_pageOverlays.size() - 1;
60 added = true;
61 }
62
63 PageOverlay* pageOverlay = m_pageOverlays[index].get();
64 pageOverlay->setZOrder(zOrder);
65
66 // Adjust page overlay list order based on their z-order numbers. We first
67 // check if we need to move the overlay up and do so if needed. Otherwise,
68 // check if we need to move it down.
69 bool zOrderChanged = false;
70 for (size_t i = index; i + 1 < m_pageOverlays.size(); ++i) {
71 if (m_pageOverlays[i]->zOrder() >= m_pageOverlays[i + 1]->zOrder()) {
72 m_pageOverlays[i].swap(m_pageOverlays[i + 1]);
73 zOrderChanged = true;
74 }
75 }
76
77 if (!zOrderChanged) {
78 for (size_t i = index; i >= 1; --i) {
79 if (m_pageOverlays[i]->zOrder() < m_pageOverlays[i - 1]->zOrder()) {
80 m_pageOverlays[i].swap(m_pageOverlays[i - 1]);
81 zOrderChanged = true;
82 }
83 }
84 }
85
86 // If we did move the overlay, that means z-order is changed and we need to
87 // update overlay layers' z-order. Otherwise, just update current overlay.
88 if (zOrderChanged) {
89 for (size_t i = 0; i < m_pageOverlays.size(); ++i)
90 m_pageOverlays[i]->clear();
91 update();
92 } else
93 pageOverlay->update();
94
95 return added;
96 }
97
98 bool PageOverlayList::remove(WebPageOverlay* overlay)
99 {
100 size_t index = find(overlay);
101 if (index == WTF::kNotFound)
102 return false;
103
104 m_pageOverlays[index]->clear();
105 m_pageOverlays.remove(index);
106 return true;
107 }
108
109 void PageOverlayList::update()
110 {
111 for (size_t i = 0; i < m_pageOverlays.size(); ++i)
112 m_pageOverlays[i]->update();
113 }
114
115 void PageOverlayList::paintWebFrame(GraphicsContext& gc)
116 {
117 // If accelerated compositing is active, page overlays are painted through
118 // their corresponding GraphicsLayer.
119 ASSERT(!m_viewImpl->isAcceleratedCompositingActive());
120 for (size_t i = 0; i < m_pageOverlays.size(); ++i)
121 m_pageOverlays[i]->paintWebFrame(gc);
122 }
123
124 size_t PageOverlayList::find(WebPageOverlay* overlay)
125 {
126 for (size_t i = 0; i < m_pageOverlays.size(); ++i) {
127 if (m_pageOverlays[i]->overlay() == overlay)
128 return i;
129 }
130 return WTF::kNotFound;
131 }
132
133 size_t PageOverlayList::findGraphicsLayer(GraphicsLayer* layer)
134 {
135 for (size_t i = 0; i < m_pageOverlays.size(); ++i) {
136 if (m_pageOverlays[i]->graphicsLayer() == layer)
137 return i;
138 }
139 return WTF::kNotFound;
140 }
141
142 GraphicsLayer* PageOverlayList::graphicsLayerForTesting() const
143 {
144 if (m_pageOverlays.isEmpty())
145 return nullptr;
146 return m_pageOverlays[0]->graphicsLayer();
147 }
148
149 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/PageOverlayList.h ('k') | Source/web/PageOverlayTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698