<commit_before>/*
 * DesktopGwtWindow.cpp
 *
 * Copyright (C) 2009-12 by RStudio, Inc.
 *
 * Unless you have received this program directly from RStudio pursuant
 * to the terms of a commercial license agreement with RStudio, then
 * this program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */

#include "DesktopGwtWindow.hpp"
#include "DesktopOptions.hpp"


namespace rstudio {
namespace desktop {

namespace {

bool isDuplicateZoomRequest(QElapsedTimer* pTimer)
{
   qint64 elapsed = pTimer->restart();
   return elapsed < 10;
}

} // end anonymous namespace

GwtWindow::GwtWindow(bool showToolbar,
                     bool adjustTitle,
                     QString name,
                     QUrl baseUrl,
                     QWidget* pParent,
                     WebPage* opener) :
   BrowserWindow(showToolbar, adjustTitle, name, baseUrl, pParent, opener)
{
   // initialize zoom levels (synchronize with AppearancePreferencesPane.java)
   double levels[] = {
      0.25, 0.50, 0.75, 0.80, 0.90,
      1.00, 1.10, 1.25, 1.50, 1.75,
      2.00, 2.50, 3.00, 4.00, 5.00
   };
   
   for (double level : levels)
      zoomLevels_.push_back(level);
   
   lastZoomTimer_.start();
}

void GwtWindow::zoomActualSize()
{
   if (isDuplicateZoomRequest(&lastZoomTimer_))
      return;
   
   options().setZoomLevel(1);
   webView()->setZoomFactor(1);
}

void GwtWindow::zoomIn()
{
   if (isDuplicateZoomRequest(&lastZoomTimer_))
      return;
   
   // get next greatest value
   double zoomLevel = options().zoomLevel();
   auto it = std::upper_bound(zoomLevels_.begin(), zoomLevels_.end(), zoomLevel);
   if (it != zoomLevels_.end())
   {
      options().setZoomLevel(*it);
      webView()->setZoomFactor(*it);
   }
}

void GwtWindow::zoomOut()
{
   if (isDuplicateZoomRequest(&lastZoomTimer_))
      return;
   
   // get next smallest value
   double zoomLevel = options().zoomLevel();
   auto it = std::lower_bound(zoomLevels_.begin(), zoomLevels_.end(), zoomLevel);
   if (it != zoomLevels_.begin() && it != zoomLevels_.end())
   {
      options().setZoomLevel(*(it - 1));
      webView()->setZoomFactor(*(it - 1));
   }
}

void GwtWindow::finishLoading(bool succeeded)
{
   BrowserWindow::finishLoading(succeeded);
}

bool GwtWindow::event(QEvent* pEvent)
{
   if (pEvent->type() == QEvent::WindowActivate)
      onActivated();

   return BrowserWindow::event(pEvent);
}

void GwtWindow::onCloseWindowShortcut()
{
   // check to see if the window has desktop hooks (not all GWT windows do); if it does, check to
   // see whether it has a closeSourceDoc() command we should be executing instead
   webPage()->runJavaScript(
            QStringLiteral(
               "if (window.desktopHooks) "
               " window.desktopHooks.isCommandEnabled('closeSourceDoc');"
               "else false"),
            [&](QVariant closeSourceDocEnabled)
   {
      if (!closeSourceDocEnabled.toBool())
         close();
   });
}


} // namespace desktop
} // namespace rstudio
<commit_msg>zoom workaround no longer required with Qt 5.11<commit_after>/*
 * DesktopGwtWindow.cpp
 *
 * Copyright (C) 2009-12 by RStudio, Inc.
 *
 * Unless you have received this program directly from RStudio pursuant
 * to the terms of a commercial license agreement with RStudio, then
 * this program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */

#include "DesktopGwtWindow.hpp"
#include "DesktopOptions.hpp"


namespace rstudio {
namespace desktop {

#if QT_VERSION_MAJOR == 5 && QT_VERSION_MINOR == 10

namespace {

bool isDuplicateZoomRequest(QElapsedTimer* pTimer)
{
   qint64 elapsed = pTimer->restart();
   return elapsed < 10;
}

} // end anonymous namespace

#endif

GwtWindow::GwtWindow(bool showToolbar,
                     bool adjustTitle,
                     QString name,
                     QUrl baseUrl,
                     QWidget* pParent,
                     WebPage* opener) :
   BrowserWindow(showToolbar, adjustTitle, name, baseUrl, pParent, opener)
{
   // initialize zoom levels (synchronize with AppearancePreferencesPane.java)
   double levels[] = {
      0.25, 0.50, 0.75, 0.80, 0.90,
      1.00, 1.10, 1.25, 1.50, 1.75,
      2.00, 2.50, 3.00, 4.00, 5.00
   };
   
   for (double level : levels)
      zoomLevels_.push_back(level);
   
   lastZoomTimer_.start();
}

void GwtWindow::zoomActualSize()
{
   
#if QT_VERSION_MAJOR == 5 && QT_VERSION_MINOR == 10
   if (isDuplicateZoomRequest(&lastZoomTimer_))
      return;
#endif
   
   options().setZoomLevel(1);
   webView()->setZoomFactor(1);
}

void GwtWindow::zoomIn()
{
   if (isDuplicateZoomRequest(&lastZoomTimer_))
      return;
   
   // get next greatest value
   double zoomLevel = options().zoomLevel();
   auto it = std::upper_bound(zoomLevels_.begin(), zoomLevels_.end(), zoomLevel);
   if (it != zoomLevels_.end())
   {
      options().setZoomLevel(*it);
      webView()->setZoomFactor(*it);
   }
}

void GwtWindow::zoomOut()
{
   if (isDuplicateZoomRequest(&lastZoomTimer_))
      return;
   
   // get next smallest value
   double zoomLevel = options().zoomLevel();
   auto it = std::lower_bound(zoomLevels_.begin(), zoomLevels_.end(), zoomLevel);
   if (it != zoomLevels_.begin() && it != zoomLevels_.end())
   {
      options().setZoomLevel(*(it - 1));
      webView()->setZoomFactor(*(it - 1));
   }
}

void GwtWindow::finishLoading(bool succeeded)
{
   BrowserWindow::finishLoading(succeeded);
}

bool GwtWindow::event(QEvent* pEvent)
{
   if (pEvent->type() == QEvent::WindowActivate)
      onActivated();

   return BrowserWindow::event(pEvent);
}

void GwtWindow::onCloseWindowShortcut()
{
   // check to see if the window has desktop hooks (not all GWT windows do); if it does, check to
   // see whether it has a closeSourceDoc() command we should be executing instead
   webPage()->runJavaScript(
            QStringLiteral(
               "if (window.desktopHooks) "
               " window.desktopHooks.isCommandEnabled('closeSourceDoc');"
               "else false"),
            [&](QVariant closeSourceDocEnabled)
   {
      if (!closeSourceDocEnabled.toBool())
         close();
   });
}


} // namespace desktop
} // namespace rstudio

{'fraction_non_alphanumeric': 0.12081233323450934, 'fraction_numerical': 0.019715386895938335, 'mean_word_length': 3.03770197486535, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4369203', 'n_tokens_mistral': 2211, 'n_tokens_neox': 2049, 'n_words': 545}