Home | History | Annotate | Download | only in frame
      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 Computer, 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 
     30 #include "config.h"
     31 #include "core/frame/Screen.h"
     32 
     33 #include "core/frame/FrameHost.h"
     34 #include "core/frame/FrameView.h"
     35 #include "core/frame/LocalFrame.h"
     36 #include "core/frame/Settings.h"
     37 #include "core/inspector/InspectorInstrumentation.h"
     38 #include "platform/PlatformScreen.h"
     39 #include "platform/geometry/FloatRect.h"
     40 
     41 namespace blink {
     42 
     43 Screen::Screen(LocalFrame* frame)
     44     : DOMWindowProperty(frame)
     45 {
     46 }
     47 
     48 unsigned Screen::height() const
     49 {
     50     if (!m_frame)
     51         return 0;
     52     FrameHost* host = m_frame->host();
     53     if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk())
     54         return lroundf(screenRect(m_frame->view()).height() * host->deviceScaleFactor());
     55     return static_cast<unsigned>(screenRect(m_frame->view()).height());
     56 }
     57 
     58 unsigned Screen::width() const
     59 {
     60     if (!m_frame)
     61         return 0;
     62     FrameHost* host = m_frame->host();
     63     if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk())
     64         return lroundf(screenRect(m_frame->view()).width() * host->deviceScaleFactor());
     65     return static_cast<unsigned>(screenRect(m_frame->view()).width());
     66 }
     67 
     68 unsigned Screen::colorDepth() const
     69 {
     70     if (!m_frame)
     71         return 0;
     72     return static_cast<unsigned>(screenDepth(m_frame->view()));
     73 }
     74 
     75 unsigned Screen::pixelDepth() const
     76 {
     77     if (!m_frame)
     78         return 0;
     79     return static_cast<unsigned>(screenDepth(m_frame->view()));
     80 }
     81 
     82 int Screen::availLeft() const
     83 {
     84     if (!m_frame)
     85         return 0;
     86     FrameHost* host = m_frame->host();
     87     if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk())
     88         return lroundf(screenAvailableRect(m_frame->view()).x() * host->deviceScaleFactor());
     89     return static_cast<int>(screenAvailableRect(m_frame->view()).x());
     90 }
     91 
     92 int Screen::availTop() const
     93 {
     94     if (!m_frame)
     95         return 0;
     96     FrameHost* host = m_frame->host();
     97     if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk())
     98         return lroundf(screenAvailableRect(m_frame->view()).y() * host->deviceScaleFactor());
     99     return static_cast<int>(screenAvailableRect(m_frame->view()).y());
    100 }
    101 
    102 unsigned Screen::availHeight() const
    103 {
    104     if (!m_frame)
    105         return 0;
    106     FrameHost* host = m_frame->host();
    107     if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk())
    108         return lroundf(screenAvailableRect(m_frame->view()).height() * host->deviceScaleFactor());
    109     return static_cast<unsigned>(screenAvailableRect(m_frame->view()).height());
    110 }
    111 
    112 unsigned Screen::availWidth() const
    113 {
    114     if (!m_frame)
    115         return 0;
    116     FrameHost* host = m_frame->host();
    117     if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk())
    118         return lroundf(screenAvailableRect(m_frame->view()).width() * host->deviceScaleFactor());
    119     return static_cast<unsigned>(screenAvailableRect(m_frame->view()).width());
    120 }
    121 
    122 void Screen::trace(Visitor* visitor)
    123 {
    124 #if ENABLE(OILPAN)
    125     HeapSupplementable<Screen>::trace(visitor);
    126 #endif
    127     DOMWindowProperty::trace(visitor);
    128 }
    129 
    130 } // namespace blink
    131