<commit_before>// Copyright (c) 2006-2008 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/views/info_bubble.h"

#include "app/gfx/canvas.h"
#include "app/gfx/color_utils.h"
#include "app/gfx/path.h"
#include "app/resource_bundle.h"
#include "chrome/browser/window_sizer.h"
#include "chrome/common/notification_service.h"
#include "grit/theme_resources.h"
#include "views/widget/root_view.h"
#include "views/window/window.h"

#if defined(OS_WIN)
#include "base/win_util.h"
#endif

using views::View;

namespace {

// All sizes are in pixels.

// Size of the border, along each edge.
const int kBorderSize = 1;

// Size of the arrow.
const int kArrowSize = 5;

// Number of pixels to the start of the arrow from the edge of the window.
const int kArrowXOffset = 13;

// Number of pixels between the tip of the arrow and the region we're
// pointing to.
const int kArrowToContentPadding = -4;

// Background color of the bubble.
#if defined(OS_WIN)
const SkColor kBackgroundColor = color_utils::GetSysSkColor(COLOR_WINDOW);
#else
// TODO(beng): source from theme provider.
const SkColor kBackgroundColor = SK_ColorWHITE;
#endif

// Color of the border and arrow.
const SkColor kBorderColor1 = SkColorSetRGB(99, 99, 99);
// Border shadow color.
const SkColor kBorderColor2 = SkColorSetRGB(160, 160, 160);

// Intended dimensions of the bubble's corner images. If you update these,
// make sure that the OnSize code works.
const int kInfoBubbleCornerWidth = 3;
const int kInfoBubbleCornerHeight = 3;

// Bubble corner images.
const SkBitmap* kInfoBubbleCornerTopLeft = NULL;
const SkBitmap* kInfoBubbleCornerTopRight = NULL;
const SkBitmap* kInfoBubbleCornerBottomLeft = NULL;
const SkBitmap* kInfoBubbleCornerBottomRight = NULL;

// Margins around the content.
const int kInfoBubbleViewTopMargin = 6;
const int kInfoBubbleViewBottomMargin = 9;
const int kInfoBubbleViewLeftMargin = 6;
const int kInfoBubbleViewRightMargin = 6;

}  // namespace

// InfoBubble -----------------------------------------------------------------

// static
InfoBubble* InfoBubble::Show(views::Window* parent,
                             const gfx::Rect& position_relative_to,
                             views::View* contents,
                             InfoBubbleDelegate* delegate) {
  InfoBubble* window = new InfoBubble();
  window->Init(parent, position_relative_to, contents, delegate);
  return window;
}

void InfoBubble::Close() {
  Close(false);
}

InfoBubble::InfoBubble()
    :
#if defined(OS_LINUX)
      WidgetGtk(TYPE_POPUP),
#endif
      delegate_(NULL),
      parent_(NULL),
      content_view_(NULL),
      closed_(false) {
}

void InfoBubble::Init(views::Window* parent,
                      const gfx::Rect& position_relative_to,
                      views::View* contents,
                      InfoBubbleDelegate* delegate) {
  parent_ = parent;
  parent_->DisableInactiveRendering();

  delegate_ = delegate;

  if (kInfoBubbleCornerTopLeft == NULL) {
    kInfoBubbleCornerTopLeft = ResourceBundle::GetSharedInstance()
        .GetBitmapNamed(IDR_INFO_BUBBLE_CORNER_TOP_LEFT);
    kInfoBubbleCornerTopRight = ResourceBundle::GetSharedInstance()
        .GetBitmapNamed(IDR_INFO_BUBBLE_CORNER_TOP_RIGHT);
    kInfoBubbleCornerBottomLeft = ResourceBundle::GetSharedInstance()
        .GetBitmapNamed(IDR_INFO_BUBBLE_CORNER_BOTTOM_LEFT);
    kInfoBubbleCornerBottomRight = ResourceBundle::GetSharedInstance()
        .GetBitmapNamed(IDR_INFO_BUBBLE_CORNER_BOTTOM_RIGHT);
  }
#if defined(OS_WIN)
  set_window_style(WS_POPUP | WS_CLIPCHILDREN);
  set_window_ex_style(WS_EX_TOOLWINDOW);
  set_initial_class_style(
      (win_util::GetWinVersion() < win_util::WINVERSION_XP) ?
      0 : CS_DROPSHADOW);
#endif
  content_view_ = CreateContentView(contents);

#if defined(OS_WIN)
  WidgetWin::Init(parent->GetNativeWindow(), gfx::Rect());
#else
  WidgetGtk::Init(GTK_WIDGET(parent->GetNativeWindow()), gfx::Rect());
#endif

  SetContentsView(content_view_);
  // The preferred size may differ when parented. Ask for the bounds again
  // and if they differ reset the bounds.
  gfx::Rect parented_bounds =
      content_view_->CalculateWindowBoundsAndAjust(position_relative_to);
  SetBounds(parented_bounds);

#if defined(OS_WIN)
  // Register the Escape accelerator for closing.
  GetFocusManager()->RegisterAccelerator(
      views::Accelerator(VK_ESCAPE, false, false, false), this);
#endif

  NotificationService::current()->Notify(NotificationType::INFO_BUBBLE_CREATED,
                                         Source<InfoBubble>(this),
                                         NotificationService::NoDetails());

  // Show the window.
#if defined(OS_WIN)
  ShowWindow(SW_SHOW);
#else
  Show();
#endif
}

InfoBubble::ContentView* InfoBubble::CreateContentView(View* content) {
  return new ContentView(content, this);
}

#if defined(OS_WIN)
void InfoBubble::OnActivate(UINT action, BOOL minimized, HWND window) {
  // The popup should close when it is deactivated.
  if (action == WA_INACTIVE && !closed_) {
    Close();
  } else if (action == WA_ACTIVE) {
    DCHECK(GetRootView()->GetChildViewCount() > 0);
    GetRootView()->GetChildViewAt(0)->RequestFocus();
  }
}

void InfoBubble::OnSize(UINT param, const CSize& size) {
  // See OnSizeAllocate for the Linux version.
  gfx::Path path;<commit_msg>Another try to fix a build break caused by r26312. This change just adds a namespace. I wish this fixes.<commit_after>// Copyright (c) 2006-2008 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/views/info_bubble.h"

#include "app/gfx/canvas.h"
#include "app/gfx/color_utils.h"
#include "app/gfx/path.h"
#include "app/resource_bundle.h"
#include "chrome/browser/window_sizer.h"
#include "chrome/common/notification_service.h"
#include "grit/theme_resources.h"
#include "views/widget/root_view.h"
#include "views/window/window.h"

#if defined(OS_WIN)
#include "base/win_util.h"
#endif

using views::View;

namespace {

// All sizes are in pixels.

// Size of the border, along each edge.
const int kBorderSize = 1;

// Size of the arrow.
const int kArrowSize = 5;

// Number of pixels to the start of the arrow from the edge of the window.
const int kArrowXOffset = 13;

// Number of pixels between the tip of the arrow and the region we're
// pointing to.
const int kArrowToContentPadding = -4;

// Background color of the bubble.
#if defined(OS_WIN)
const SkColor kBackgroundColor = color_utils::GetSysSkColor(COLOR_WINDOW);
#else
// TODO(beng): source from theme provider.
const SkColor kBackgroundColor = SK_ColorWHITE;
#endif

// Color of the border and arrow.
const SkColor kBorderColor1 = SkColorSetRGB(99, 99, 99);
// Border shadow color.
const SkColor kBorderColor2 = SkColorSetRGB(160, 160, 160);

// Intended dimensions of the bubble's corner images. If you update these,
// make sure that the OnSize code works.
const int kInfoBubbleCornerWidth = 3;
const int kInfoBubbleCornerHeight = 3;

// Bubble corner images.
const SkBitmap* kInfoBubbleCornerTopLeft = NULL;
const SkBitmap* kInfoBubbleCornerTopRight = NULL;
const SkBitmap* kInfoBubbleCornerBottomLeft = NULL;
const SkBitmap* kInfoBubbleCornerBottomRight = NULL;

// Margins around the content.
const int kInfoBubbleViewTopMargin = 6;
const int kInfoBubbleViewBottomMargin = 9;
const int kInfoBubbleViewLeftMargin = 6;
const int kInfoBubbleViewRightMargin = 6;

}  // namespace

// InfoBubble -----------------------------------------------------------------

// static
InfoBubble* InfoBubble::Show(views::Window* parent,
                             const gfx::Rect& position_relative_to,
                             views::View* contents,
                             InfoBubbleDelegate* delegate) {
  InfoBubble* window = new InfoBubble();
  window->Init(parent, position_relative_to, contents, delegate);
  return window;
}

void InfoBubble::Close() {
  Close(false);
}

InfoBubble::InfoBubble()
    :
#if defined(OS_LINUX)
      WidgetGtk(TYPE_POPUP),
#endif
      delegate_(NULL),
      parent_(NULL),
      content_view_(NULL),
      closed_(false) {
}

void InfoBubble::Init(views::Window* parent,
                      const gfx::Rect& position_relative_to,
                      views::View* contents,
                      InfoBubbleDelegate* delegate) {
  parent_ = parent;
  parent_->DisableInactiveRendering();

  delegate_ = delegate;

  if (kInfoBubbleCornerTopLeft == NULL) {
    kInfoBubbleCornerTopLeft = ResourceBundle::GetSharedInstance()
        .GetBitmapNamed(IDR_INFO_BUBBLE_CORNER_TOP_LEFT);
    kInfoBubbleCornerTopRight = ResourceBundle::GetSharedInstance()
        .GetBitmapNamed(IDR_INFO_BUBBLE_CORNER_TOP_RIGHT);
    kInfoBubbleCornerBottomLeft = ResourceBundle::GetSharedInstance()
        .GetBitmapNamed(IDR_INFO_BUBBLE_CORNER_BOTTOM_LEFT);
    kInfoBubbleCornerBottomRight = ResourceBundle::GetSharedInstance()
        .GetBitmapNamed(IDR_INFO_BUBBLE_CORNER_BOTTOM_RIGHT);
  }
#if defined(OS_WIN)
  set_window_style(WS_POPUP | WS_CLIPCHILDREN);
  set_window_ex_style(WS_EX_TOOLWINDOW);
  set_initial_class_style(
      (win_util::GetWinVersion() < win_util::WINVERSION_XP) ?
      0 : CS_DROPSHADOW);
#endif
  content_view_ = CreateContentView(contents);

#if defined(OS_WIN)
  WidgetWin::Init(parent->GetNativeWindow(), gfx::Rect());
#else
  WidgetGtk::Init(GTK_WIDGET(parent->GetNativeWindow()), gfx::Rect());
#endif

  SetContentsView(content_view_);
  // The preferred size may differ when parented. Ask for the bounds again
  // and if they differ reset the bounds.
  gfx::Rect parented_bounds =
      content_view_->CalculateWindowBoundsAndAjust(position_relative_to);
  SetBounds(parented_bounds);

#if defined(OS_WIN)
  // Register the Escape accelerator for closing.
  GetFocusManager()->RegisterAccelerator(
      views::Accelerator(VK_ESCAPE, false, false, false), this);
#endif

  NotificationService::current()->Notify(NotificationType::INFO_BUBBLE_CREATED,
                                         Source<InfoBubble>(this),
                                         NotificationService::NoDetails());

  // Show the window.
#if defined(OS_WIN)
  ShowWindow(SW_SHOW);
#else
  views::WidgetGtk::Show();
#endif
}

InfoBubble::ContentView* InfoBubble::CreateContentView(View* content) {
  return new ContentView(content, this);
}

#if defined(OS_WIN)
void InfoBubble::OnActivate(UINT action, BOOL minimized, HWND window) {
  // The popup should close when it is deactivated.
  if (action == WA_INACTIVE && !closed_) {
    Close();
  } else if (action == WA_ACTIVE) {
    DCHECK(GetRootView()->GetChildViewCount() > 0);
    GetRootView()->GetChildViewAt(0)->RequestFocus();
  }
}

void InfoBubble::OnSize(UINT param, const CSize& size) {
  // See OnSizeAllocate for the Linux version.
  gfx::Path path;
{'fraction_non_alphanumeric': 0.1146374829001368, 'fraction_numerical': 0.00756953944368445, 'mean_word_length': 3.782381160052333, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2869250', 'n_tokens_mistral': 3491, 'n_tokens_neox': 3394, 'n_words': 846}