This source file includes following definitions.
- create
- add
- remove
- update
- paintWebFrame
- find
- findGraphicsLayer
#include "config.h"
#include "PageOverlayList.h"
#include "PageOverlay.h"
#include "WebPageOverlay.h"
#include "WebViewImpl.h"
namespace blink {
PassOwnPtr<PageOverlayList> PageOverlayList::create(WebViewImpl* viewImpl)
{
return adoptPtr(new PageOverlayList(viewImpl));
}
PageOverlayList::PageOverlayList(WebViewImpl* viewImpl)
: m_viewImpl(viewImpl)
{
}
PageOverlayList::~PageOverlayList()
{
}
bool PageOverlayList::add(WebPageOverlay* overlay, int zOrder)
{
bool added = false;
size_t index = find(overlay);
if (index == WTF::kNotFound) {
OwnPtr<PageOverlay> pageOverlay = PageOverlay::create(m_viewImpl, overlay);
m_pageOverlays.append(pageOverlay.release());
index = m_pageOverlays.size() - 1;
added = true;
}
PageOverlay* pageOverlay = m_pageOverlays[index].get();
pageOverlay->setZOrder(zOrder);
bool zOrderChanged = false;
for (size_t i = index; i + 1 < m_pageOverlays.size(); ++i) {
if (m_pageOverlays[i]->zOrder() >= m_pageOverlays[i + 1]->zOrder()) {
m_pageOverlays[i].swap(m_pageOverlays[i + 1]);
zOrderChanged = true;
}
}
if (!zOrderChanged) {
for (size_t i = index; i >= 1; --i) {
if (m_pageOverlays[i]->zOrder() < m_pageOverlays[i - 1]->zOrder()) {
m_pageOverlays[i].swap(m_pageOverlays[i - 1]);
zOrderChanged = true;
}
}
}
if (zOrderChanged) {
for (size_t i = 0; i < m_pageOverlays.size(); ++i)
m_pageOverlays[i]->clear();
update();
} else
pageOverlay->update();
return added;
}
bool PageOverlayList::remove(WebPageOverlay* overlay)
{
size_t index = find(overlay);
if (index == WTF::kNotFound)
return false;
m_pageOverlays[index]->clear();
m_pageOverlays.remove(index);
return true;
}
void PageOverlayList::update()
{
for (size_t i = 0; i < m_pageOverlays.size(); ++i)
m_pageOverlays[i]->update();
}
void PageOverlayList::paintWebFrame(WebCore::GraphicsContext& gc)
{
for (size_t i = 0; i < m_pageOverlays.size(); ++i)
m_pageOverlays[i]->paintWebFrame(gc);
}
size_t PageOverlayList::find(WebPageOverlay* overlay)
{
for (size_t i = 0; i < m_pageOverlays.size(); ++i) {
if (m_pageOverlays[i]->overlay() == overlay)
return i;
}
return WTF::kNotFound;
}
size_t PageOverlayList::findGraphicsLayer(WebCore::GraphicsLayer* layer)
{
for (size_t i = 0; i < m_pageOverlays.size(); ++i) {
if (m_pageOverlays[i]->graphicsLayer() == layer)
return i;
}
return WTF::kNotFound;
}
}