summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/web_intent_picker_cocoa.mm
blob: ff9b467f810f906a6495a54f389cdfae27be5847 (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
// 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/cocoa/web_intent_picker_cocoa.h"

#import <Cocoa/Cocoa.h>

#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
#import "chrome/browser/ui/cocoa/web_intent_bubble_controller.h"
#include "chrome/browser/ui/intents/web_intent_picker.h"
#include "chrome/browser/ui/intents/web_intent_picker_delegate.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "skia/ext/skia_utils_mac.h"

// static
WebIntentPicker* WebIntentPicker::Create(Browser* browser,
                                         TabContentsWrapper* wrapper,
                                         WebIntentPickerDelegate* delegate) {
  return new WebIntentPickerCocoa(browser, wrapper, delegate);
}

WebIntentPickerCocoa::WebIntentPickerCocoa(Browser* browser,
                                           TabContentsWrapper* wrapper,
                                           WebIntentPickerDelegate* delegate)
   : delegate_(delegate),
     controller_(NULL) {
  DCHECK(browser);
  DCHECK(delegate);
  NSWindow* parentWindow = browser->window()->GetNativeHandle();

  // Compute the anchor point, relative to location bar.
  BrowserWindowController* controller = [parentWindow windowController];
  LocationBarViewMac* locationBar = [controller locationBarBridge];
  NSPoint anchor = locationBar->GetPageInfoBubblePoint();
  anchor = [browser->window()->GetNativeHandle() convertBaseToScreen:anchor];

  // The controller is deallocated when the window is closed, so no need to
  // worry about it here.
  [[WebIntentBubbleController alloc] initWithPicker:this
                                       parentWindow:parentWindow
                                         anchoredAt:anchor];
}

void WebIntentPickerCocoa::SetServiceURLs(const std::vector<GURL>& urls) {
}

void WebIntentPickerCocoa::SetServiceIcon(size_t index, const SkBitmap& icon) {
  DCHECK(controller_);
  if (icon.empty())
    return;

  NSImage* image = gfx::SkBitmapToNSImage(icon);
  [controller_ replaceImageAtIndex:index withImage:image];
}

void WebIntentPickerCocoa::SetDefaultServiceIcon(size_t index) {
}

void WebIntentPickerCocoa::Close() {
}

WebIntentPickerCocoa::~WebIntentPickerCocoa() {
}

void WebIntentPickerCocoa::OnCancelled() {
  DCHECK(delegate_);
  delegate_->OnCancelled();
  controller_ = NULL;  // Controller will be unusable soon, abandon.
}

void WebIntentPickerCocoa::OnServiceChosen(size_t index) {
  DCHECK(delegate_);
  delegate_->OnServiceChosen(index);
}

void WebIntentPickerCocoa::set_controller(
    WebIntentBubbleController* controller) {
  controller_ = controller;
}