summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/browser_bubble_win.cc
blob: 8cae2daf3e8fa1cf3cefaafed592f94e9f74f401 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// 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/browser_bubble.h"

#include "app/l10n_util_win.h"
#include "chrome/browser/views/frame/browser_view.h"
#include "views/widget/root_view.h"
#include "views/widget/widget_win.h"
#include "views/window/window.h"

class BubbleWidget : public views::WidgetWin
{
public:
  BubbleWidget(BrowserBubble* bubble) : bubble_(bubble), closed_(false) {
  }

  void Show(bool activate) {
    if (activate)
      ShowWindow(SW_SHOW);
    else
      views::WidgetWin::Show();
  }

  void Close() {
    if (closed_)
      return;
    closed_ = true;
    views::WidgetWin::Close();
  }

  void OnActivate(UINT action, BOOL minimized, HWND window) {
    BrowserBubble::Delegate* delegate = bubble_->delegate();
    if (!delegate)
      return;

    if (action == WA_INACTIVE && !closed_) {
      delegate->BubbleLostFocus(bubble_);
    } else if (action == WA_ACTIVE) {
      delegate->BubbleGotFocus(bubble_);
    }
  }

private:
  bool closed_;
  BrowserBubble* bubble_;
};

void BrowserBubble::InitPopup() {
  gfx::NativeWindow native_window = frame_->GetWindow()->GetNativeWindow();

  // popup_ is a Widget, but we need to do some WidgetWin stuff first, then
  // we'll assign it into popup_.
  views::WidgetWin* pop = new BubbleWidget(this);
  pop->set_window_style(WS_POPUP);

#if 0
  // TODO(erikkay) Layered windows don't draw child windows.
  // Apparently there's some tricks you can do to handle that.
  // Do the research so we can use this.
  pop->set_window_ex_style(WS_EX_LAYERED |
                           l10n_util::GetExtendedTooltipStyles());
  pop->SetOpacity(0xFF);
#endif

  // A focus manager is necessary if you want to be able to handle various
  // mouse events properly.
  pop->Init(frame_native_view_, bounds_);
  pop->SetContentsView(view_);

  popup_ = pop;
  Reposition();
  AttachToBrowser();
}

void BrowserBubble::MovePopup(int x, int y, int w, int h) {
  views::WidgetWin* pop = static_cast<views::WidgetWin*>(popup_);
  pop->MoveWindow(x, y, w, h);
}

void BrowserBubble::Show(bool activate) {
  if (visible_)
    return;
  BubbleWidget* pop = static_cast<BubbleWidget*>(popup_);
  pop->Show(activate);
  visible_ = true;
}

void BrowserBubble::Hide() {
  if (!visible_)
    return;
  views::WidgetWin* pop = static_cast<views::WidgetWin*>(popup_);
  pop->Hide();
  visible_ = false;
}