<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/global_error_bubble_view.h"

#include "base/logging.h"
#include "chrome/browser/ui/global_error.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/toolbar_view.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h"
#include "views/controls/button/text_button.h"
#include "views/controls/image_view.h"
#include "views/controls/label.h"
#include "views/layout/grid_layout.h"
#include "views/layout/layout_constants.h"

namespace {

enum {
  TAG_ACCEPT_BUTTON = 1,
  TAG_CANCEL_BUTTON,
};

const int kBubbleViewWidth = 262;

// The vertical offset of the wrench bubble from the wrench menu button.
const int kWrenchBubblePointOffsetY = 6;

} // namespace

GlobalErrorBubbleView::GlobalErrorBubbleView(Browser* browser,
                                             GlobalError* error)
    : browser_(browser),
      error_(error) {
  ResourceBundle& rb = ResourceBundle::GetSharedInstance();
  int resource_id = error_->GetBubbleViewIconResourceID();
  scoped_ptr<views::ImageView> image_view(new views::ImageView());
  image_view->SetImage(rb.GetImageNamed(resource_id).ToSkBitmap());

  string16 title_string(error_->GetBubbleViewTitle());
  scoped_ptr<views::Label> title_label(
      new views::Label(UTF16ToWideHack(title_string)));
  title_label->SetMultiLine(true);
  title_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
  title_label->SetFont(title_label->font().DeriveFont(1));

  string16 message_string(error_->GetBubbleViewMessage());
  scoped_ptr<views::Label> message_label(
      new views::Label(UTF16ToWideHack(message_string)));
  message_label->SetMultiLine(true);
  message_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);

  string16 accept_string(error_->GetBubbleViewAcceptButtonLabel());
  scoped_ptr<views::TextButton> accept_button(
      new views::NativeTextButton(this, UTF16ToWideHack(accept_string)));
  accept_button->SetIsDefault(true);

  string16 cancel_string(error_->GetBubbleViewCancelButtonLabel());
  scoped_ptr<views::TextButton> cancel_button;
  if (!cancel_string.empty()) {
    cancel_button.reset(
        new views::NativeTextButton(this, UTF16ToWideHack(cancel_string)));
  }

  views::GridLayout* layout = new views::GridLayout(this);
  SetLayoutManager(layout);

  // Top row, icon and title.
  views::ColumnSet* cs = layout->AddColumnSet(0);
  cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING,
                0, views::GridLayout::USE_PREF, 0, 0);
  cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL,
                1, views::GridLayout::USE_PREF, 0, 0);

  // Middle row, message label.
  cs = layout->AddColumnSet(1);
  cs->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
                1, views::GridLayout::USE_PREF, 0, 0);

  // Bottom row, accept and cancel button.
  cs = layout->AddColumnSet(2);
  cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing);
  cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING,
                0, views::GridLayout::USE_PREF, 0, 0);
  cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
  cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING,
                0, views::GridLayout::USE_PREF, 0, 0);

  layout->StartRow(1, 0);<commit_msg>Fix layout of global error bubble view on windows<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/global_error_bubble_view.h"

#include "base/logging.h"
#include "chrome/browser/ui/global_error.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/toolbar_view.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h"
#include "views/controls/button/text_button.h"
#include "views/controls/image_view.h"
#include "views/controls/label.h"
#include "views/layout/grid_layout.h"
#include "views/layout/layout_constants.h"

namespace {

enum {
  TAG_ACCEPT_BUTTON = 1,
  TAG_CANCEL_BUTTON,
};

const int kBubbleViewWidth = 262;

// The horizontal padding between the title and the icon.
const int kTitleHorizontalPadding = 3;

// The vertical offset of the wrench bubble from the wrench menu button.
const int kWrenchBubblePointOffsetY = 6;

} // namespace

GlobalErrorBubbleView::GlobalErrorBubbleView(Browser* browser,
                                             GlobalError* error)
    : browser_(browser),
      error_(error) {
  ResourceBundle& rb = ResourceBundle::GetSharedInstance();
  int resource_id = error_->GetBubbleViewIconResourceID();
  scoped_ptr<views::ImageView> image_view(new views::ImageView());
  image_view->SetImage(rb.GetImageNamed(resource_id).ToSkBitmap());

  string16 title_string(error_->GetBubbleViewTitle());
  scoped_ptr<views::Label> title_label(
      new views::Label(UTF16ToWideHack(title_string)));
  title_label->SetMultiLine(true);
  title_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
  title_label->SetFont(title_label->font().DeriveFont(1));

  string16 message_string(error_->GetBubbleViewMessage());
  scoped_ptr<views::Label> message_label(
      new views::Label(UTF16ToWideHack(message_string)));
  message_label->SetMultiLine(true);
  message_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);

  string16 accept_string(error_->GetBubbleViewAcceptButtonLabel());
  scoped_ptr<views::TextButton> accept_button(
      new views::NativeTextButton(this, UTF16ToWideHack(accept_string)));
  accept_button->SetIsDefault(true);

  string16 cancel_string(error_->GetBubbleViewCancelButtonLabel());
  scoped_ptr<views::TextButton> cancel_button;
  if (!cancel_string.empty()) {
    cancel_button.reset(
        new views::NativeTextButton(this, UTF16ToWideHack(cancel_string)));
  }

  views::GridLayout* layout = new views::GridLayout(this);
  SetLayoutManager(layout);

  // Top row, icon and title.
  views::ColumnSet* cs = layout->AddColumnSet(0);
  cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING,
                0, views::GridLayout::USE_PREF, 0, 0);
  cs->AddPaddingColumn(0, kTitleHorizontalPadding);
  cs->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
                1, views::GridLayout::USE_PREF, 0, 0);

  // Middle row, message label.
  cs = layout->AddColumnSet(1);
  cs->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
                1, views::GridLayout::USE_PREF, 0, 0);

  // Bottom row, accept and cancel button.
  cs = layout->AddColumnSet(2);
  cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing);
  cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING,
                0, views::GridLayout::USE_PREF, 0, 0);
  cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
  cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING,
                0, views::GridLayout::USE_PREF, 0, 0);

  layout->StartRow(1, 0);
{'fraction_non_alphanumeric': 0.13337940566689702, 'fraction_numerical': 0.01354526606772633, 'mean_word_length': 5.137404580152672, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7654210', 'n_tokens_mistral': 2373, 'n_tokens_neox': 2289, 'n_words': 408}