Home | History | Annotate | Download | only in win
      1 /*
      2  * Copyright (C) 2011 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  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
     14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     23  * THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #include "PluginTest.h"
     27 
     28 #include "PluginObject.h"
     29 
     30 using namespace std;
     31 
     32 // The rect passed in the WM_PAINT event for a windowless plugin should be relative to the page's
     33 // HWND and clipped to the plugin's bounds.
     34 
     35 class WindowlessPaintRectCoordinates : public PluginTest {
     36 public:
     37     WindowlessPaintRectCoordinates(NPP, const string& identifier);
     38 
     39 private:
     40     virtual NPError NPP_New(NPMIMEType, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData*);
     41     virtual int16_t NPP_HandleEvent(void* event);
     42 };
     43 
     44 static PluginTest::Register<WindowlessPaintRectCoordinates> registrar("windowless-paint-rect-coordinates");
     45 
     46 WindowlessPaintRectCoordinates::WindowlessPaintRectCoordinates(NPP npp, const string& identifier)
     47     : PluginTest(npp, identifier)
     48 {
     49 }
     50 
     51 NPError WindowlessPaintRectCoordinates::NPP_New(NPMIMEType, uint16_t, int16_t, char*[], char*[], NPSavedData*)
     52 {
     53     browser->setvalue(m_npp, NPPVpluginWindowBool, 0);
     54     return NPERR_NO_ERROR;
     55 }
     56 
     57 int16_t WindowlessPaintRectCoordinates::NPP_HandleEvent(void* typelessEvent)
     58 {
     59     NPEvent* event = static_cast<NPEvent*>(typelessEvent);
     60     if (!event) {
     61         pluginLog(m_npp, "NPP_HandleEvent was passed a null event pointer");
     62         return 0;
     63     }
     64 
     65     if (event->event != WM_PAINT)
     66         return 0;
     67 
     68     RECT* paintRect = reinterpret_cast<RECT*>(event->lParam);
     69     if (!paintRect) {
     70         pluginLog(m_npp, "A null paint rect was passed in the WM_PAINT event");
     71         return 1;
     72     }
     73 
     74     // Keep these values in sync with windowless-paint-rect-coordinates.html.
     75     RECT expectedRect = { 100, 100, 200, 200 };
     76 
     77     if (::EqualRect(paintRect, &expectedRect))
     78         pluginLog(m_npp, "Success");
     79     else
     80         pluginLog(m_npp, "Expected paint rect {left=%d, top=%d, right=%d, bottom=%d}, but got {left=%d, top=%d, right=%d, bottom=%d}", expectedRect.left, expectedRect.top, expectedRect.right, expectedRect.bottom, paintRect->left, paintRect->top, paintRect->right, paintRect->bottom);
     81 
     82     return 1;
     83 }
     84