Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(340)

Side by Side Diff: chrome/browser/ui/intents/web_intent_picker.cc

Issue 10411010: [Gtk, WebIntents] Support autosizing of inline content. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/intents/web_intent_picker.h" 5 #include "chrome/browser/ui/intents/web_intent_picker.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
10 #include "content/public/browser/web_contents_view.h" 10 #include "content/public/browser/web_contents_view.h"
11 #include "grit/theme_resources.h" 11 #include "grit/theme_resources.h"
12 #include "ui/gfx/size.h" 12 #include "ui/gfx/size.h"
13 13
14 namespace { 14 namespace {
15 15
16 // The minimum width of the inline disposition tab contents. 16 // The minimum width of the inline disposition tab contents.
17 const int kMinInlineDispositionWidth = 300; 17 const int kMinInlineDispositionWidth = 300;
18 18
19 // The minimum height of the inline disposition tab contents. 19 // The minimum height of the inline disposition tab contents.
20 const int kMinInlineDispositionHeight = 300; 20 const int kMinInlineDispositionHeight = 300;
21 21
22 // Maximum inline disposition container sizes.
23 const int kMaxInlineDispositionWidth = 900;
24 const int kMaxInlineDispositionHeight = 900;
25
22 } // namespace 26 } // namespace
23 27
24 // static 28 // static
25 gfx::Size WebIntentPicker::GetDefaultInlineDispositionSize( 29 gfx::Size WebIntentPicker::GetDefaultInlineDispositionSize(
26 content::WebContents* web_contents) { 30 content::WebContents* web_contents) {
27 // TODO(gbillock): This size calculation needs more thought. 31 // TODO(gbillock): This size calculation needs more thought.
28 gfx::Size tab_size = web_contents->GetView()->GetContainerSize(); 32 gfx::Size tab_size = web_contents->GetView()->GetContainerSize();
29 int width = std::max(tab_size.width()/2, kMinInlineDispositionWidth); 33 int width = std::max(tab_size.width()/2, kMinInlineDispositionWidth);
30 int height = std::max(tab_size.height()/2, kMinInlineDispositionHeight); 34 int height = std::max(tab_size.height()/2, kMinInlineDispositionHeight);
31 35
32 return gfx::Size(width, height); 36 return gfx::Size(width, height);
33 } 37 }
34 38
35 // static 39 // static
40 gfx::Size WebIntentPicker::GetMinInlineDispositionSize() {
41 return gfx::Size(kMinInlineDispositionWidth, kMinInlineDispositionHeight);
42 }
43
44 // static
45 gfx::Size WebIntentPicker::GetMaxInlineDispositionSize() {
46 return gfx::Size(kMaxInlineDispositionWidth, kMaxInlineDispositionHeight);
47 }
48
49 // static
36 int WebIntentPicker::GetNthStarImageIdFromCWSRating(double rating, int index) { 50 int WebIntentPicker::GetNthStarImageIdFromCWSRating(double rating, int index) {
37 // The fractional part of the rating is converted to stars as: 51 // The fractional part of the rating is converted to stars as:
38 // [0, 0.33) -> round down 52 // [0, 0.33) -> round down
39 // [0.33, 0.66] -> half star 53 // [0.33, 0.66] -> half star
40 // (0.66, 1) -> round up 54 // (0.66, 1) -> round up
41 const double kHalfStarMin = 0.33; 55 const double kHalfStarMin = 0.33;
42 const double kHalfStarMax = 0.66; 56 const double kHalfStarMax = 0.66;
43 57
44 // Add 1 + kHalfStarMax to make values with fraction > 0.66 round up. 58 // Add 1 + kHalfStarMax to make values with fraction > 0.66 round up.
45 int full_stars = std::floor(rating + 1 - kHalfStarMax); 59 int full_stars = std::floor(rating + 1 - kHalfStarMax);
46 60
47 if (index < full_stars) 61 if (index < full_stars)
48 return IDR_CWS_STAR_FULL; 62 return IDR_CWS_STAR_FULL;
49 63
50 // We don't need to test against the upper bound (kHalfStarMax); when the 64 // We don't need to test against the upper bound (kHalfStarMax); when the
51 // fractional part is greater than kHalfStarMax, full_stars will be rounded 65 // fractional part is greater than kHalfStarMax, full_stars will be rounded
52 // up, which means rating - full_stars is negative. 66 // up, which means rating - full_stars is negative.
53 bool half_star = rating - full_stars >= kHalfStarMin; 67 bool half_star = rating - full_stars >= kHalfStarMin;
54 68
55 return index == full_stars && half_star ? 69 return index == full_stars && half_star ?
56 IDR_CWS_STAR_HALF : 70 IDR_CWS_STAR_HALF :
57 IDR_CWS_STAR_EMPTY; 71 IDR_CWS_STAR_EMPTY;
58 } 72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698