1/*
2 * Copyright (C) 2007 Apple 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
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include "config.h"
30#include "Screen.h"
31
32#include "FloatRect.h"
33#include "Frame.h"
34#include "FrameView.h"
35#include "PlatformScreen.h"
36#include "ResourceLoadObserver.h"
37#include "RuntimeEnabledFeatures.h"
38#include <wtf/IsoMallocInlines.h>
39
40namespace WebCore {
41
42WTF_MAKE_ISO_ALLOCATED_IMPL(Screen);
43
44Screen::Screen(DOMWindow& window)
45 : DOMWindowProperty(&window)
46{
47}
48
49unsigned Screen::height() const
50{
51 auto* frame = this->frame();
52 if (!frame)
53 return 0;
54 if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
55 ResourceLoadObserver::shared().logScreenAPIAccessed(*frame->document(), ResourceLoadStatistics::ScreenAPI::Height);
56 long height = static_cast<long>(screenRect(frame->view()).height());
57 return static_cast<unsigned>(height);
58}
59
60unsigned Screen::width() const
61{
62 auto* frame = this->frame();
63 if (!frame)
64 return 0;
65 if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
66 ResourceLoadObserver::shared().logScreenAPIAccessed(*frame->document(), ResourceLoadStatistics::ScreenAPI::Width);
67 long width = static_cast<long>(screenRect(frame->view()).width());
68 return static_cast<unsigned>(width);
69}
70
71unsigned Screen::colorDepth() const
72{
73 auto* frame = this->frame();
74 if (!frame)
75 return 0;
76 if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
77 ResourceLoadObserver::shared().logScreenAPIAccessed(*frame->document(), ResourceLoadStatistics::ScreenAPI::ColorDepth);
78 return static_cast<unsigned>(screenDepth(frame->view()));
79}
80
81unsigned Screen::pixelDepth() const
82{
83 auto* frame = this->frame();
84 if (!frame)
85 return 0;
86 if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
87 ResourceLoadObserver::shared().logScreenAPIAccessed(*frame->document(), ResourceLoadStatistics::ScreenAPI::PixelDepth);
88 return static_cast<unsigned>(screenDepth(frame->view()));
89}
90
91int Screen::availLeft() const
92{
93 auto* frame = this->frame();
94 if (!frame)
95 return 0;
96 if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
97 ResourceLoadObserver::shared().logScreenAPIAccessed(*frame->document(), ResourceLoadStatistics::ScreenAPI::AvailLeft);
98 return static_cast<int>(screenAvailableRect(frame->view()).x());
99}
100
101int Screen::availTop() const
102{
103 auto* frame = this->frame();
104 if (!frame)
105 return 0;
106 if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
107 ResourceLoadObserver::shared().logScreenAPIAccessed(*frame->document(), ResourceLoadStatistics::ScreenAPI::AvailTop);
108 return static_cast<int>(screenAvailableRect(frame->view()).y());
109}
110
111unsigned Screen::availHeight() const
112{
113 auto* frame = this->frame();
114 if (!frame)
115 return 0;
116 if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
117 ResourceLoadObserver::shared().logScreenAPIAccessed(*frame->document(), ResourceLoadStatistics::ScreenAPI::AvailHeight);
118 return static_cast<unsigned>(screenAvailableRect(frame->view()).height());
119}
120
121unsigned Screen::availWidth() const
122{
123 auto* frame = this->frame();
124 if (!frame)
125 return 0;
126 if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
127 ResourceLoadObserver::shared().logScreenAPIAccessed(*frame->document(), ResourceLoadStatistics::ScreenAPI::AvailWidth);
128 return static_cast<unsigned>(screenAvailableRect(frame->view()).width());
129}
130
131} // namespace WebCore
132