summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/new_browser_window_widget.cc
blob: c8d3cf786e1949399abd2fc4b14612da44c9c9cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2009 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/new_browser_window_widget.h"

#include "app/resource_bundle.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/views/tabs/tab_overview_types.h"
#include "chrome/common/page_transition_types.h"
#include "googleurl/src/gurl.h"
#include "grit/theme_resources.h"
#include "views/controls/button/image_button.h"
#include "views/fill_layout.h"
#include "views/widget/root_view.h"
#include "views/widget/widget_gtk.h"

NewBrowserWindowWidget::NewBrowserWindowWidget(Profile* profile)
    : profile_(profile),
      widget_(NULL) {
  views::ImageButton* button = new views::ImageButton(this);
  button->SetImage(views::CustomButton::BS_NORMAL,
                   ResourceBundle::GetSharedInstance().GetBitmapNamed(
                       IDR_NEW_BROWSER_WINDOW_ICON));
  gfx::Size pref = button->GetPreferredSize();
  views::WidgetGtk* widget =
      new views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW);
  widget->MakeTransparent();
  widget->Init(NULL, gfx::Rect(0, 0, pref.width(), pref.height()));
  TabOverviewTypes::instance()->SetWindowType(
      widget->GetNativeView(),
      TabOverviewTypes::WINDOW_TYPE_CREATE_BROWSER_WINDOW,
      NULL);
  widget->GetRootView()->SetLayoutManager(new views::FillLayout());
  widget->GetRootView()->AddChildView(button);
  widget_ = widget;
  widget->Show();
}

NewBrowserWindowWidget::~NewBrowserWindowWidget() {
  widget_->Close();
  widget_ = NULL;
}

void NewBrowserWindowWidget::ButtonPressed(
    views::Button* sender, const views::Event& event) {
  UserMetrics::RecordAction(L"TabOverview_PressedCreateNewBrowserButton",
                            profile_);

  Browser* browser = Browser::Create(profile_);
  browser->AddTabWithURL(GURL(), GURL(), PageTransition::START_PAGE,
                         true, -1, false, NULL);
  browser->window()->Show();
}