<commit_before>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h"

#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/ui/views/bubble/bubble.h"
#include "grit/generated_resources.h"
#include "ui/base/animation/slide_animation.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/screen.h"
#include "views/bubble/bubble_border.h"
#include "views/controls/button/text_button.h"
#include "views/controls/link.h"
#include "views/widget/widget.h"

#if defined(OS_WIN)
#include "ui/base/l10n/l10n_util_win.h"
#endif

// FullscreenExitView ----------------------------------------------------------

namespace {
// Space between the site info label and the buttons / link.
const int kMiddlePaddingPx = 30;
}  // namespace

class FullscreenExitBubbleViews::FullscreenExitView
    : public views::View,
      public views::ButtonListener {
 public:
  FullscreenExitView(FullscreenExitBubbleViews* bubble,
                     const string16& accelerator,
                     const GURL& url,
                     bool ask_permission);
  virtual ~FullscreenExitView();

  // views::View
  virtual gfx::Size GetPreferredSize();

  // views::ButtonListener
  virtual void ButtonPressed(views::Button* sender, const views::Event& event);

  // Hide the accept and deny buttons, exposing the exit link.
  void HideButtons();

 private:
  string16 GetMessage(const GURL& url);

  // views::View
  virtual void Layout();

  FullscreenExitBubbleViews* bubble_;

  // Clickable hint text to show in the bubble.
  views::Link link_;
  views::Label message_label_;
  views::NativeTextButton* accept_button_;
  views::NativeTextButton* deny_button_;

  bool show_buttons_;
};

FullscreenExitBubbleViews::FullscreenExitView::FullscreenExitView(
    FullscreenExitBubbleViews* bubble,
    const string16& accelerator,
    const GURL& url,
    bool ask_permission)
    : bubble_(bubble),
      accept_button_(NULL),
      deny_button_(NULL),
      show_buttons_(ask_permission) {
  views::BubbleBorder* bubble_border =
      new views::BubbleBorder(views::BubbleBorder::NONE);
  bubble_border->set_background_color(Bubble::kBackgroundColor);
  set_background(new views::BubbleBackground(bubble_border));
  set_border(bubble_border);
  set_focusable(false);

  message_label_.set_parent_owned(false);
  message_label_.SetText(GetMessage(url));
  message_label_.SetFont(ResourceBundle::GetSharedInstance().GetFont(
      ResourceBundle::MediumFont));

  link_.set_parent_owned(false);
  link_.set_collapse_when_hidden(false);
  link_.set_focusable(false);
#if !defined(OS_CHROMEOS)
  link_.SetText(
      l10n_util::GetStringFUTF16(IDS_EXIT_FULLSCREEN_MODE,
                                 accelerator));
#else
  link_.SetText(l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE));
#endif
  link_.set_listener(bubble);
  link_.SetFont(ResourceBundle::GetSharedInstance().GetFont(
      ResourceBundle::MediumFont));
  link_.SetPressedColor(message_label_.enabled_color());
  link_.SetEnabledColor(message_label_.enabled_color());
  link_.SetVisible(false);

  link_.SetBackgroundColor(background()->get_color());
  message_label_.SetBackgroundColor(background()->get_color());
  AddChildView(&message_label_);
  AddChildView(&link_);

  accept_button_ = new views::NativeTextButton(this,
      UTF16ToWide(l10n_util::GetStringUTF16(IDS_FULLSCREEN_INFOBAR_ALLOW)));
  accept_button_->set_focusable(false);
  AddChildView(accept_button_);

  deny_button_ = new views::NativeTextButton(this,
      UTF16ToWide(l10n_util::GetStringUTF16(IDS_FULLSCREEN_INFOBAR_DENY)));
  deny_button_->set_focusable(false);
  AddChildView(deny_button_);

  if (!show_buttons_)
    HideButtons();
}

string16 FullscreenExitBubbleViews::FullscreenExitView::GetMessage(
    const GURL& url) {
  if (url.is_empty()) {
    return l10n_util::GetStringUTF16(
        IDS_FULLSCREEN_INFOBAR_USER_ENTERED_FULLSCREEN);
  }
  if (url.SchemeIsFile())
    return l10n_util::GetStringUTF16(IDS_FULLSCREEN_INFOBAR_FILE_PAGE_NAME);
  return l10n_util::GetStringFUTF16(IDS_FULLSCREEN_INFOBAR_REQUEST_PERMISSION,
      UTF8ToUTF16(url.host()));
}

FullscreenExitBubbleViews::FullscreenExitView::~FullscreenExitView() {
}

void FullscreenExitBubbleViews::FullscreenExitView::ButtonPressed(
    views::Button* sender, const views::Event& event) {
  if (sender == accept_button_)
    bubble_->OnAcceptFullscreen();
  else
    bubble_->OnCancelFullscreen();
}

void FullscreenExitBubbleViews::FullscreenExitView::HideButtons() {
  show_buttons_ = false;
  accept_button_->SetVisible(false);
  deny_button_->SetVisible(false);
  link_.SetVisible(true);
}

gfx::Size FullscreenExitBubbleViews::FullscreenExitView::GetPreferredSize() {
  gfx::Size link_size(link_.GetPreferredSize());
  gfx::Size message_label_size(message_label_.GetPreferredSize());
  gfx::Size accept_size(accept_button_->GetPreferredSize());
  gfx::Size deny_size(deny_button_->GetPreferredSize());
  gfx::Insets insets(GetInsets());

  int buttons_width = accept_size.width() + kPaddingPx +
      deny_size.width();
  int button_box_width = std::max(buttons_width, link_size.width());
  int width = kPaddingPx + message_label_size.width() + kMiddlePaddingPx +
      button_box_width + kPaddingPx;

  gfx::Size result(width + insets.width(),
      kPaddingPx * 2 + accept_size.height() + insets.height());
  return result;
}

void FullscreenExitBubbleViews::FullscreenExitView::Layout() {
  gfx::Size link_size(link_.GetPreferredSize());
  gfx::Size message_label_size(message_label_.GetPreferredSize());
  gfx::Size accept_size(accept_button_->GetPreferredSize());
  gfx::Size deny_size(deny_button_->GetPreferredSize());
  gfx::Insets insets(GetInsets());

  int inner_height = height() - insets.height();
  int button_box_x = insets.left() + kPaddingPx +
      message_label_size.width() + kMiddlePaddingPx;
  int message_label_y = insets.top() +
      (inner_height - message_label_size.height()) / 2;
  int link_x = width() - insets.right() - kPaddingPx -
      link_size.width();
  int link_y = insets.top() + (inner_height - link_size.height()) / 2;

  message_label_.SetPosition(gfx::Point(insets.left() + kPaddingPx,
                             message_label_y));
  link_.SetPosition(gfx::Point(link_x, link_y));
  if (show_buttons_) {
    accept_button_->SetPosition(gfx::Point(button_box_x,
        insets.top() + kPaddingPx));
    deny_button_->SetPosition(gfx::Point(
        button_box_x + accept_size.width() + kPaddingPx,
        insets.top() + kPaddingPx));
  }
}

// FullscreenExitBubbleViews ---------------------------------------------------

FullscreenExitBubbleViews::FullscreenExitBubbleViews(views::Widget* frame,
                                                     Browser* browser,
                                                     const GURL& url,
                                                     bool ask_permission)
    : FullscreenExitBubble(browser),
      root_view_(frame->GetRootView()),
      popup_(NULL),
      size_animation_(new ui::SlideAnimation(this)),<commit_msg>Change SetPosition() to SetBounds() in FullscreenExitView::Layout().<commit_after>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h"

#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/ui/views/bubble/bubble.h"
#include "grit/generated_resources.h"
#include "ui/base/animation/slide_animation.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/screen.h"
#include "views/bubble/bubble_border.h"
#include "views/controls/button/text_button.h"
#include "views/controls/link.h"
#include "views/widget/widget.h"

#if defined(OS_WIN)
#include "ui/base/l10n/l10n_util_win.h"
#endif

// FullscreenExitView ----------------------------------------------------------

namespace {
// Space between the site info label and the buttons / link.
const int kMiddlePaddingPx = 30;
}  // namespace

class FullscreenExitBubbleViews::FullscreenExitView
    : public views::View,
      public views::ButtonListener {
 public:
  FullscreenExitView(FullscreenExitBubbleViews* bubble,
                     const string16& accelerator,
                     const GURL& url,
                     bool ask_permission);
  virtual ~FullscreenExitView();

  // views::View
  virtual gfx::Size GetPreferredSize();

  // views::ButtonListener
  virtual void ButtonPressed(views::Button* sender, const views::Event& event);

  // Hide the accept and deny buttons, exposing the exit link.
  void HideButtons();

 private:
  string16 GetMessage(const GURL& url);

  // views::View
  virtual void Layout();

  FullscreenExitBubbleViews* bubble_;

  // Clickable hint text to show in the bubble.
  views::Link link_;
  views::Label message_label_;
  views::NativeTextButton* accept_button_;
  views::NativeTextButton* deny_button_;

  bool show_buttons_;
};

FullscreenExitBubbleViews::FullscreenExitView::FullscreenExitView(
    FullscreenExitBubbleViews* bubble,
    const string16& accelerator,
    const GURL& url,
    bool ask_permission)
    : bubble_(bubble),
      accept_button_(NULL),
      deny_button_(NULL),
      show_buttons_(ask_permission) {
  views::BubbleBorder* bubble_border =
      new views::BubbleBorder(views::BubbleBorder::NONE);
  bubble_border->set_background_color(Bubble::kBackgroundColor);
  set_background(new views::BubbleBackground(bubble_border));
  set_border(bubble_border);
  set_focusable(false);

  message_label_.set_parent_owned(false);
  message_label_.SetText(GetMessage(url));
  message_label_.SetFont(ResourceBundle::GetSharedInstance().GetFont(
      ResourceBundle::MediumFont));

  link_.set_parent_owned(false);
  link_.set_collapse_when_hidden(false);
  link_.set_focusable(false);
#if !defined(OS_CHROMEOS)
  link_.SetText(
      l10n_util::GetStringFUTF16(IDS_EXIT_FULLSCREEN_MODE,
                                 accelerator));
#else
  link_.SetText(l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE));
#endif
  link_.set_listener(bubble);
  link_.SetFont(ResourceBundle::GetSharedInstance().GetFont(
      ResourceBundle::MediumFont));
  link_.SetPressedColor(message_label_.enabled_color());
  link_.SetEnabledColor(message_label_.enabled_color());
  link_.SetVisible(false);

  link_.SetBackgroundColor(background()->get_color());
  message_label_.SetBackgroundColor(background()->get_color());
  AddChildView(&message_label_);
  AddChildView(&link_);

  accept_button_ = new views::NativeTextButton(this,
      UTF16ToWide(l10n_util::GetStringUTF16(IDS_FULLSCREEN_INFOBAR_ALLOW)));
  accept_button_->set_focusable(false);
  AddChildView(accept_button_);

  deny_button_ = new views::NativeTextButton(this,
      UTF16ToWide(l10n_util::GetStringUTF16(IDS_FULLSCREEN_INFOBAR_DENY)));
  deny_button_->set_focusable(false);
  AddChildView(deny_button_);

  if (!show_buttons_)
    HideButtons();
}

string16 FullscreenExitBubbleViews::FullscreenExitView::GetMessage(
    const GURL& url) {
  if (url.is_empty()) {
    return l10n_util::GetStringUTF16(
        IDS_FULLSCREEN_INFOBAR_USER_ENTERED_FULLSCREEN);
  }
  if (url.SchemeIsFile())
    return l10n_util::GetStringUTF16(IDS_FULLSCREEN_INFOBAR_FILE_PAGE_NAME);
  return l10n_util::GetStringFUTF16(IDS_FULLSCREEN_INFOBAR_REQUEST_PERMISSION,
      UTF8ToUTF16(url.host()));
}

FullscreenExitBubbleViews::FullscreenExitView::~FullscreenExitView() {
}

void FullscreenExitBubbleViews::FullscreenExitView::ButtonPressed(
    views::Button* sender, const views::Event& event) {
  if (sender == accept_button_)
    bubble_->OnAcceptFullscreen();
  else
    bubble_->OnCancelFullscreen();
}

void FullscreenExitBubbleViews::FullscreenExitView::HideButtons() {
  show_buttons_ = false;
  accept_button_->SetVisible(false);
  deny_button_->SetVisible(false);
  link_.SetVisible(true);
}

gfx::Size FullscreenExitBubbleViews::FullscreenExitView::GetPreferredSize() {
  gfx::Size link_size(link_.GetPreferredSize());
  gfx::Size message_label_size(message_label_.GetPreferredSize());
  gfx::Size accept_size(accept_button_->GetPreferredSize());
  gfx::Size deny_size(deny_button_->GetPreferredSize());
  gfx::Insets insets(GetInsets());

  int buttons_width = accept_size.width() + kPaddingPx +
      deny_size.width();
  int button_box_width = std::max(buttons_width, link_size.width());
  int width = kPaddingPx + message_label_size.width() + kMiddlePaddingPx +
      button_box_width + kPaddingPx;

  gfx::Size result(width + insets.width(),
      kPaddingPx * 2 + accept_size.height() + insets.height());
  return result;
}

void FullscreenExitBubbleViews::FullscreenExitView::Layout() {
  gfx::Size link_size(link_.GetPreferredSize());
  gfx::Size message_label_size(message_label_.GetPreferredSize());
  gfx::Size accept_size(accept_button_->GetPreferredSize());
  gfx::Size deny_size(deny_button_->GetPreferredSize());
  gfx::Insets insets(GetInsets());

  int inner_height = height() - insets.height();
  int button_box_x = insets.left() + kPaddingPx +
      message_label_size.width() + kMiddlePaddingPx;
  int message_label_y = insets.top() +
      (inner_height - message_label_size.height()) / 2;
  int link_x = width() - insets.right() - kPaddingPx -
      link_size.width();
  int link_y = insets.top() + (inner_height - link_size.height()) / 2;

  message_label_.SetBounds(insets.left() + kPaddingPx,
                           message_label_y,
                           message_label_size.width(),
                           message_label_size.height());
  link_.SetBounds(link_x,
                  link_y,
                  link_size.width(),
                  link_size.height());
  if (show_buttons_) {
    accept_button_->SetBounds(button_box_x,
                              insets.top() + kPaddingPx,
                              accept_size.width(),
                              accept_size.height());
    deny_button_->SetBounds(button_box_x + accept_size.width() + kPaddingPx,
                            insets.top() + kPaddingPx,
                            deny_size.width(),
                            deny_size.height());
  }
}

// FullscreenExitBubbleViews ---------------------------------------------------

FullscreenExitBubbleViews::FullscreenExitBubbleViews(views::Widget* frame,
                                                     Browser* browser,
                                                     const GURL& url,
                                                     bool ask_permission)
    : FullscreenExitBubble(browser),
      root_view_(frame->GetRootView()),
      popup_(NULL),
      size_animation_(new ui::SlideAnimation(this)),
{'fraction_non_alphanumeric': 0.12873427672955975, 'fraction_numerical': 0.007861635220125786, 'mean_word_length': 3.9083601286173635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3746044', 'n_tokens_mistral': 4833, 'n_tokens_neox': 4745, 'n_words': 741}