Ejemplo n.º 1
0
  private void initSkin(Class<? extends BrowserSimSkin> skinClass, Point location) {
    try {
      skin = skinClass.newInstance(); // new AppleIPhone3Skin();//new NativeSkin();
    } catch (InstantiationException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (IllegalAccessException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    skin.setBrowserFactory(new WebKitBrowserFactory());

    Display display = Display.getDefault();

    try {
      skin.createControls(display, location);
      currentLocation = location;
    } catch (SWTError e) {
      e.printStackTrace();
      ExceptionNotifier.showWebKitLoadError(new Shell(display), e);
      display.dispose();
      return;
    }

    final Shell shell = skin.getShell();
    resizableSkinSizeAdvisor =
        new ResizableSkinSizeAdvisorImpl(commonPreferences, specificPreferences, shell);
    shell.addControlListener(
        new ControlAdapter() {
          @Override
          public void controlMoved(ControlEvent e) {
            currentLocation = shell.getLocation();
            super.controlMoved(e);
          }
        });

    shell.addListener(
        SWT.Close,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            instances.remove(BrowserSim.this);
            specificPreferences.setLocation(currentLocation);
            SpecificPreferencesStorage.INSTANCE.save(specificPreferences);
            if (instances.isEmpty()) {
              CommonPreferencesStorage.INSTANCE.save(commonPreferences);
            }
            commonPreferences.deleteObserver(commonPreferencesObserver);
          }
        });

    shell.addListener(
        SWT.Close,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            for (ExitListener e : exitListenerList) {
              e.exit();
            }
          }
        });

    final BrowserSimBrowser browser = getBrowser();
    controlHandler = createControlHandler(browser, homeUrl, specificPreferences);
    final BrowserSimMenuCreator menuCreator =
        createMenuCreator(skin, commonPreferences, specificPreferences, controlHandler, homeUrl);

    shell.addShellListener(
        new ShellListener() {
          @Override
          public void shellIconified(ShellEvent e) {}

          @Override
          public void shellDeiconified(ShellEvent e) {}

          @Override
          public void shellDeactivated(ShellEvent e) {}

          @Override
          public void shellClosed(ShellEvent e) {}

          @Override
          public void shellActivated(ShellEvent e) {
            // adding menu on activation to make it working properly on every sync window
            menuCreator.addMenuBar();
          }
        });
    menuCreator.addMenuBar();
    setShellAttibutes();

    skin.setControlHandler(controlHandler);

    Menu contextMenu = new Menu(shell);
    skin.setContextMenu(contextMenu);
    menuCreator.createMenuItemsForContextMenu(contextMenu);

    progressListener =
        new ProgressListener() {
          public void changed(ProgressEvent event) {
            int ratio;
            if (event.current == event.total || event.total == 0) {
              ratio = -1;
            } else {
              ratio = event.current * 100 / event.total;
            }
            skin.progressChanged(ratio);
          }

          public void completed(ProgressEvent event) {
            skin.progressChanged(-1);
          }
        };
    browser.addProgressListener(progressListener);

    browser.addStatusTextListener(
        new StatusTextListener() {
          public void changed(StatusTextEvent event) {
            skin.statusTextChanged(event.text);
          }
        });
    browser.addLocationListener(
        new LocationListener() {
          public void changed(LocationEvent event) {
            if (event.top) {
              BrowserSimBrowser browser = (BrowserSimBrowser) event.widget;
              skin.locationChanged(
                  event.location, browser.isBackEnabled(), browser.isForwardEnabled());
            }
          }

          public void changing(LocationEvent event) {}
        });

    browser.addLocationListener(
        new LocationAdapter() {
          public void changed(LocationEvent event) {
            initOrientation(specificPreferences.getOrientationAngle());
            WebSqlLoader.initWebSql(skin.getBrowser());
          }
        });

    // JBIDE-12191 - custom scrollbars work satisfactorily on windows only
    if (PlatformUtil.OS_WIN32.equals(PlatformUtil.getOs())) {
      browser.addLocationListener(
          new LocationAdapter() {
            @Override
            public void changed(LocationEvent event) {
              Browser browser = (Browser) event.widget;
              setCustomScrollbarStyles(browser);
            }

            @SuppressWarnings("nls")
            private void setCustomScrollbarStyles(Browser browser) {

              browser.execute(
                  "if (window._browserSim_customScrollBarStylesSetter === undefined) {"
                      + "window._browserSim_customScrollBarStylesSetter = function () {"
                      + "document.removeEventListener('DOMSubtreeModified', window._browserSim_customScrollBarStylesSetter, false);"
                      + "var head = document.head;"
                      + "var style = document.createElement('style');"
                      + "style.type = 'text/css';"
                      + "style.id='browserSimStyles';"
                      + "head.appendChild(style);"
                      + "style.innerText='"
                      // The following two rules fix a problem with showing scrollbars in Google
                      // Mail and similar,
                      // but autohiding of navigation bar stops to work with it. That is why they
                      // are commented.
                      // +	"html {"
                      // +		"overflow: hidden;"
                      // +	"}"
                      // +	"body {"
                      // +		"position: absolute;"
                      // +		"top: 0px;"
                      // +		"left: 0px;"
                      // +		"bottom: 0px;"
                      // +		"right: 0px;"
                      // +		"margin: 0px;"
                      // +		"overflow-y: auto;"
                      // +		"overflow-x: auto;"
                      // +	"}"
                      + "::-webkit-scrollbar {"
                      + "width: 5px;"
                      + "height: 5px;"
                      + "}"
                      + "::-webkit-scrollbar-thumb {"
                      + "background: rgba(0,0,0,0.4); "
                      + "}"
                      + "::-webkit-scrollbar-corner, ::-webkit-scrollbar-thumb:window-inactive {"
                      + "background: rgba(0,0,0,0.0);"
                      + "};"
                      + "';"
                      + "};"
                      + "document.addEventListener('DOMSubtreeModified', window._browserSim_customScrollBarStylesSetter, false);"
                      + "}");
            }
          });
    }
    ;

    browser.addOpenWindowListener(
        new OpenWindowListener() {
          public void open(WindowEvent event) {
            if (FireBugLiteLoader.isFireBugPopUp(event)) {
              FireBugLiteLoader.processFireBugPopUp(event);
            } else {
              event.browser = browser;
            }
          }
        });

    browser.addLocationListener(
        new LocationListener() {
          private BrowserFunction scrollListener = null;

          @SuppressWarnings("nls")
          public void changed(LocationEvent event) {
            if (scrollListener != null) {
              scrollListener.dispose();
            }
            scrollListener =
                new BrowserFunction(((Browser) event.widget), "_browserSim_scrollListener") {
                  public Object function(Object[] arguments) {
                    double pageYOffset = (Double) arguments[0];
                    if (pageYOffset > 0.0) {
                      skin.getShell()
                          .getDisplay()
                          .asyncExec(
                              new Runnable() {
                                public void run() {
                                  if (skin != null
                                      && skin.getShell() != null
                                      && !skin.getShell().isDisposed()) {
                                    skin.setAddressBarVisible(false);
                                  }
                                }
                              });
                    }
                    return null;
                  }
                };

            Browser browser = (Browser) event.widget;
            browser.execute(
                "(function() {"
                    + "var scrollListener = function(e){"
                    + "window._browserSim_scrollListener(window.pageYOffset)"
                    + "};"
                    + "window.addEventListener('scroll', scrollListener);"
                    + "window.addEventListener('beforeunload', function(e){"
                    + "window.removeEventListener('scroll', scrollListener);"
                    + "delete window._browserSim_scrollListener;"
                    + "})"
                    + "})();");
          }

          public void changing(LocationEvent event) {
            skin.setAddressBarVisible(true);
          }
        });

    browser.addLocationListener(
        new LocationAdapter() {
          @Override
          public void changed(LocationEvent event) {
            if (getBrowser().equals(Display.getDefault().getFocusControl()) && event.top) {
              for (BrowserSim bs : instances) {
                if (bs.skin != skin) {
                  bs.skin.getBrowser().setUrl(event.location);
                }
              }
            }
          }
        });

    browser.addTitleListener(
        new TitleListener() {
          @Override
          public void changed(TitleEvent event) {
            skin.pageTitleChanged(event.title);
          }
        });
  }
Ejemplo n.º 2
0
 @Override
 protected void failed(Throwable cause) {
   setMessage("Regression failed.");
   ExceptionNotifier.notifyError(cause);
 }